I want to execute the python script from java using shell commands file location: d:/python/test.py
below is my java program
def callstme(){
Process p
try {
List<String> cmdList = new ArrayList<String>();
cmdList.add("sh");
cmdList.add("d:/python/test.py");
ProcessBuilder pb = new ProcessBuilder(cmdList);
p = pb.start();
p.waitFor();
BufferedReader reader=new BufferedReader(new InputStreamReader(
p.getInputStream()));
String line;
while((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
while executing I'm getting the error
"java.io.IOException: Cannot run program "sh": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
shto an executable file or script or whatever. Maybe the directory containingshcommand is not in thePATH... that is being passed in the child process environment. Maybeshis not installed. (You appear to be using Windows!!) Maybe it is a permissions problem of some kind. Try using the absolute path for theshcommand instead. (Typically/bin/sh... on a UNIX / Linux system.) Or on Windows ... maybe you should be usingcmd.exeinstead ofsh?