Reputation: 7469
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: Cannot run program "prog" error=13, Permission denied.
I have already checked file permissions:
-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();
}
Upvotes: 1
Views: 2822
Reputation: 3666
When invoking bash scripts from java you must specify '/bin/bash' as the executable and pass your script path as an argument.
Upvotes: 2