我试图运行使用JDK7u25的CMD文件,下面的代码:执行文件夹中包含CMD文件与空间
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);
}
其中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"]
但它不工作,我得到下面的输出。
“C:\我的”不被识别为内部或外部的命令,
运行的程序或批处理文件。
在调用cmd文件之前,我已经通过添加显式的“CMD.EXE/C”对JDK7U21 issue进行了必要的更改。另外我也使用了JDK7u21问题中提到的ProcessBuilder类。
如果我试图执行CMD文件被放置在C中,它工作得很好:\ MyRoot即一个文件夹,没有它的名字空间。
有人可以帮忙吗?
这是因为'cmd'需要用引号括起来'路径 “C:\我的根\脚本\ WINDOWS \工具\ MyCLI.cmd”'和' “C:\本地磁盘d \我的教程\ RegressionTests.xml” '通过Windows – dic19