在Eclipse中执行bash脚本 [英] Execute bash script in eclipse
问题描述
我试图弄清楚如何从eclipse中的JAVA程序中执行一个简单的bash脚本.我已经检查了一些问题,例如无法运行程序".../abc.exe":错误= 13,权限被拒绝和
I'm trying to figure out how to execute a simple bash script from a JAVA program inside eclipse. I have already checked some questions like Cannot run program "..../abc.exe": error=13, Permission denied and Permission denied when running shell script from java program, but still I have this error:
IOException:无法运行程序"prog",错误= 13,权限被拒绝.
IOException: Cannot run program "prog" error=13, Permission denied.
我已经检查了文件权限:
I have already checked file permissions:
-rwxrwxr-x用户用户编
-rwxrwxr-x user user prog
我使用以下代码片段执行脚本:
I use this snippet to execute the script:
File file = new File(this.getClass().getClassLoader().getResource("prog").getFile());
ProcessBuilder processBuilder = new ProcessBuilder(file.getAbsolutePath());
try {
Process process = processBuilder.start();
process.waitFor();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
推荐答案
从Java调用bash脚本时,必须将'/bin/bash'指定为可执行文件,并将脚本路径作为参数传递.
When invoking bash scripts from java you must specify '/bin/bash' as the executable and pass your script path as an argument.
这篇关于在Eclipse中执行bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!