I have a shell script file that i want to run from java. My java work space directory is different than the script\'s directory.
private final String script
Your program clean.sh
is not an executable as Java understands it, even though the underlying system understands it as executable.
You need to tell Java what shell is needed to execute your command. Do (assuming you are using bash
and it is installed at /bin/bash
):
private final String scriptPath = "/home/kemallin/Desktop/";
public void cleanCSVScript() {
String script = "clean.sh";
try {
Process awk = new ProcessBuilder("/bin/bash", scriptPath + script).start();
awk.waitFor();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
You should do a chmod 755 /home/kemallin/Desktop/clean.sh
and ensure the java process is run under the same userid