Antonio La Marra
Antonio La Marra

Reputation: 7469

Execute bash script in eclipse

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

Answers (1)

ccarton
ccarton

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

Related Questions