Reputation: 3728
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)
Upvotes: 1
Views: 559