我正在尝试使用 Runtime.getrunTime().exec 从另一个 java 程序运行 java 程序
代码:
String java_home = System.getenv("JAVA_HOME");
String[] command = {""+java_home+"/bin/java -cp -cp /sc/sug/p-lib/* Tdesigner -cd /pr -in ing.rsp -out /scratch/sug/ng.pla -ad -stopO "};
try {
proc = Runtime.getRuntime().exec(command);
proc.waitFor();
int exitCode = proc.exitValue();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
它给我以下错误:
java.io.IOException: Cannot run program "/net/sl/sc/jdk6/bin/java -cp /sc/sug/p-lib/* Tdesigner -cd /pr -in ing.rsp -out /scratch/sug/ng.pla -ad -stopOnError ": java.io.IOException: error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:466)
谁能帮我解决这个问题。我是否需要使用 -cp 添加单个 jar 文件而不是设置目录。
最佳答案
尝试从命令字符串数组中删除多余的 -cp
并在数组中使用单独的标记:
String[] command = { java_home + "/bin/java", "-cp",
"/sc/sug/p-lib/*", "Tdesigner", "-cd", "/pr", "-in", "ing.rsp",
"-out", "/scratch/sug/ng.pla", "-ad", "-stopO" };
关于java.io.IOException : error=2, 没有那个文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12904640/