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)
你打印错了文件名?
d:/python/test.pyy
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.