I'm trying to run a script from Java. I tried doing this in my main class.
ProcessBuilder pb = new ProcessBuilder("./test_exec.sh", "hello world");
Process p = pb.start();
I'm building the project through maven and test_exec.sh is included as a resource. When I unarchive the jar, I see the test_exec.sh file at the root directory. Why can't Java see the file? I've also tried test_exec.sh
without the ./
in front of it.
The error I get is:
Cannot run program "./test_exec.sh": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
I've also tried:
Path currentPath = Paths.get("", "test_exec.sh").toAbsolutePath();
ProcessBuilder pb = new ProcessBuilder(currentPath.toString(), "hello world");
Process p = pb.start();