I'm writing a Java program MyAwesomeProgram that uses Process' exec function to run bash commands locally. My code is located in /home/a/b/c, and there are .sh files located in /home/a/b/d that I need to run. However, when I run my code:
Process p;
Runtime rt = new Runtime.getRuntime();
p = rt.exec("./home/a/b/d/shell.sh");
p.waitFor();
I receive an error:
Exception in thread "main" java.io.IOException: Cannot run program "./home/a/b/d/shell.sh": java.io.IOException: error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:431)
at java.lang.Runtime.exec(Runtime.java:328)
at MyAwesomeProgram.main(MyAwesomeProgram.java:186)
Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.<init>(UNIXProcess.java:148)
at java.lang.ProcessImpl.start(ProcessImpl.java:65)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
I believe this is just a mistake in formatting the exec command String, however I haven't been able to find a solution thus far. Where have I messed up? Any other tips/tricks for using exec effectively would be appreciated, but completely optional. Thanks!
Edit: I got the code working, it was an issue with a couple directory references I got backwards as well as what Woot4Moo said.