import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Demo1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Process proc;
try {
proc = Runtime.getRuntime().exec("python D:\\demo1.py");// 执行py文件
//用输入输出流来截取结果
BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
proc.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
参考:
https://blog.csdn.net/qq_35240555/article/details/123563947
标签:调用,java,python,io,import,line,proc From: https://www.cnblogs.com/northli/p/17510824.html