简体   繁体   English

java.io.IOException: error=2, 没有那个文件或目录

[英]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.

相关问题 java.io.IOException: 无法运行程序“...”: java.io.IOException: error=2, No such file or directory - java.io.IOException: Cannot run program “…”: java.io.IOException: error=2, No such file or directory Java.io.IOException:错误= 2,在Java中执行curl时没有此类文件或目录 - Java.io.IOException: error=2, No such file or directory on executing curl in java Java,由:java.io.IOException: error=2, No such file or directory - Java, Caused by: java.io.IOException: error=2, No such file or directory File.createTempFile(错误:java.io.IOException:没有这样的文件或目录) - File.createTempFile (Error: java.io.IOException: No such file or directory) 错误:java.io.IOException:android 11 中没有此类文件或目录 - Error: java.io.IOException: No such file or directory in android 11 java.io.IOException:无法运行程序“/usr/bin/sh”:java.io.IOException:error=2,没有那个文件或目录 - java.io.IOException: Cannot run program “/usr/bin/sh”: java.io.IOException: error=2, No such file or directory java.io.IOException:无法运行程序“ C:\\ AutoIt \\ ModenaAutoIt.exe”:java.io.IOException:error = 2,没有此类文件或目录 - java.io.IOException: Cannot run program “C:\AutoIt\ModenaAutoIt.exe”: java.io.IOException: error=2, No such file or directory java.io.IOException:java.io.FileNotFoundException :(无此类文件或目录) - java.io.IOException: java.io.FileNotFoundException:(No such file or directory) 无法制作文件 java.io.IOException: 没有这样的文件或目录 - Cannot make file java.io.IOException: No such file or directory 无法启动测试系统'slim':java.io.IOException:无法运行程序“ java”:error = 2,没有这样的文件或目录 - Unable to start test system 'slim': java.io.IOException: Cannot run program “java”: error=2, No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM