java.io.IOException: 无法运行程序 "": CreateProcess error=2,系统找不到指定的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25508024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.io.IOException: Cannot run program "": CreateProcess error=2, The system cannot find the file specified
提问by Doc Holiday
Im just trying to test running a shell script thats in my project directory in Eclipse.
我只是想测试运行 Eclipse 中我的项目目录中的 shell 脚本。
new ProcessBuilder("scripts/test.sh").start();
Getting this error:
收到此错误:
java.io.IOException: Cannot run program "scripts/test.sh": CreateProcess error=2, The system cannot find the file specified
java.io.IOException:无法运行程序“scripts/test.sh”:CreateProcess error=2,系统找不到指定的文件
回答by NoDataFound
This could be for two reasons:
这可能有两个原因:
- Java execute a system/exec C routine, which except a binary.
test.sh
is nota binary. You should probably use bash:bash -f scripts/test.sh
->new ProcessBuilder()("bash", "-f", new File("scripts/test.sh").getAbsoluteFile());
- The file
scripts/test.sh
does not exists, meaning the current directory is not good.
- Java 执行一个 system/exec C 例程,除了一个二进制文件。
test.sh
是不是二进制。您可能应该使用 bash:bash -f scripts/test.sh
->new ProcessBuilder()("bash", "-f", new File("scripts/test.sh").getAbsoluteFile());
- 文件
scripts/test.sh
不存在,表示当前目录不好。
You can try System.out.println(new File("scripts/test.sh").getAbsoluteFile())
to print the path Java is using.
您可以尝试System.out.println(new File("scripts/test.sh").getAbsoluteFile())
打印 Java 正在使用的路径。