[英]java.io.IOException: error=2, No such file or directory
I am trying to run a java program from another java program using Runtime.getrunTime().exec我正在尝试使用 Runtime.getrunTime().exec 从另一个 java 程序运行 java 程序
Code :代码 :
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();
}
It gives me following error:它给了我以下错误:
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)
Can anyone help me to solve the issue.谁能帮我解决这个问题。 is it that i need to add individual jar files with -cp rather than setting the directory.是不是我需要用 -cp 添加单个 jar 文件而不是设置目录。
Try removing the extra -cp
from the command string array and use individual tokens in the array:尝试从命令字符串数组中删除额外的-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" };
如果您使用 exec(String[]) ,则必须在单独的数组元素中提供命令及其参数,而不是像您所做的那样全部提供。
I use scala.我使用斯卡拉。 Here is my code:这是我的代码:
Runtime.getRuntime.exec(Array("/bin/bash", "-c", #your_command)).waitFor()
I think it is easy to understand for others who use java.我认为对于使用java的其他人来说很容易理解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.