通过本文主要向大家介绍了java调用python脚本,java执行python脚本,python与java,python与java对比,python和java的区别等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
public class Main {
public static void main(String[] args) {
try {
System.out.println("start");
Process pr = Runtime.getRuntime().exec("python test.py");
BufferedReader in = new BufferedReader(new InputStreamReader(
pr.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
pr.waitFor();
System.out.println("end");
} catch (Exception e) {
e.printStackTrace();
}
}
}
</div>
如果在eclipse中直接运行报如下错误:
java.io.IOException: Cannot run program "python": CreateProcess error=2
则配置Run Configuration中的Enviroment,增加PATH变量,见下图:


