Doc Holiday
Doc Holiday

Reputation: 10254

java.io.IOException: Cannot run program "": CreateProcess error=2, The system cannot find the file specified

Im just trying to test running a shell script thats in my project directory in Eclipse.

new ProcessBuilder("scripts/test.sh").start();

enter image description here

Getting this error:

java.io.IOException: Cannot run program "scripts/test.sh": CreateProcess error=2, The system cannot find the file specified

Upvotes: 1

Views: 27564

Answers (1)

NoDataFound
NoDataFound

Reputation: 11949

This could be for two reasons:

  • Java execute a system/exec C routine, which except a binary. test.sh is not a 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.

You can try System.out.println(new File("scripts/test.sh").getAbsoluteFile()) to print the path Java is using.

Upvotes: 5

Related Questions