I’m having some problems with getting the .getruntime.exec() to work properly. Here is the code dealing with that part:
while (line != null)
{
String name = line;
String commandFull = commandFirst + name + commandLast;
String[] fullCommand = new String[] {commandFirst, name, commandLast};
for(int i=0;i<3;i++)
{
System.out.print(fullCommand[i]);
}
Runtime runner = Runtime.getRuntime();
Process p = runner.exec(fullCommand);
outFile.println(fullCommand);
line = inFile.readLine();
}
It prints out the command as it should look. When I run the program here is the output:
adfind -b dc=stuff,dc=com -f "cn=user" |find "displayName" >> fullList.txt
Exception in thread "main" java.lang.IllegalArgumentException
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at lookup.main(lookup.java:41)
You are trying to execute a shell command without the shell.
That is, you are trying to execute something that a shell would interpret (specifically the pipe
'|'and append'>>'). To solve this, have Java execute a shell instance and pass the entire command to the shell. How this would work is platform dependent.For instance in Linux:
Or in Windows: