I have a shell script file that I want to run from java. My java workspace directory is different from the script directory.
private final String scriptPath = "/home/kemallin/Desktop/"; public void cleanCSVScript() { String script = "clean.sh"; try { Process awk = new ProcessBuilder(scriptPath + script).start(); awk.waitFor(); } catch (IOException e) {
and I get this error:
java.io.IOException: Cannot run program "cat /home/kemallin/Desktop/capture-03.csv | awk -F ',' '{ print $1,",", $2,",", $3,",", $4,",", $6}' > clean.csv": error=2, No such file or directory at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047) at ShellScript.cleanCSVScript(ShellScript.java:21) at Main.main(Main.java:15) Caused by: java.io.IOException: error=2, No such file or directory at java.lang.UNIXProcess.forkAndExec(Native Method) at java.lang.UNIXProcess.<init>(UNIXProcess.java:186) at java.lang.ProcessImpl.start(ProcessImpl.java:130) at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028) ... 2 more java.io.FileNotFoundException: /home/kemallin/Desktop/clean.csv (No such file or directory) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:146) at java.io.FileInputStream.<init>(FileInputStream.java:101) at java.io.FileReader.<init>(FileReader.java:58) at CSVReader.run(CSVReader.java:25) at Main.main(Main.java:17)
I have googled, and every decision pretty much indicates that I'm doing the right thing.
I tried to put the script file in src and in the bin of the Java project, but still it does not talk about this file or directory.
What am I doing wrong?
Thanks.
source share