I am trying to run the cmd file using JDK7u25 with following code:
try {
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.directory(workingDir);
proc = pb.start();
} catch (IOException e) {
System.out.println(e.getMessage());
throw e;
}
// StdOut and Err Stream must be read immediatly even if they are not used
// any error message?
StreamInlet error = new StreamInlet(proc.getErrorStream(), "ERROR");
// any output?
StreamInlet output = new StreamInlet(proc.getInputStream(), "OUTPUT");
// kick them off
error.start();
output.start();
if (wait) {
try {
exitCode = proc.waitFor();
} catch (InterruptedException e) {
System.out.println("Waiting for process was interrupted");
}
if (addMetaInfo)
System.out.println("Return value = " + exitCode);
}
where cmd=[cmd.exe, /c, C:\My Root\scripts\windows\tools\MyCLI.cmd, -c, C:\Local Disk D\My Tutorial\RegressionTests.xml, -d, 02_RecordViewer_Test, -l"ERROR"]
But it doesn't work and I get following output.
'C:\My' is not recognized as an internal or external command,
operable program or batch file.
I have already made the necessary changes for JDK7U21 issue by adding explicit "CMD.EXE /C" before calling the cmd file. Also I am using the ProcessBuilder class too as mentioned in the JDK7u21 issue.
It works fine if the cmd file I am trying to execute is placed in C:\MyRoot i.e. a folder without space in it's name.
Can someone please help?
I just noticed that this issue has already been addressed in JDK7u25. I just found it in it's Release Notes.
I'd be tempted to change the backslashes to forwards slashes, and escape the spaces.
You need to enclose your paths in quotation marks as
cmd
requires:Update as we discussed via chat, the problem seems to be
ProcessBuilder
passing parameters tocmd.exe
. But as you have the complete path to your executable, actuallycmd.exe
is no needed at all. So the command would look like this: