代码如下:
import java.io.BufferedRea<strong style="color:transparent">本文来源gao@daima#com搞(%代@#码网@</strong>der;<BR>import java.io.InputStreamReader;</P><P>public class Main {<BR> public static void main(String[] args) {<BR> try {<BR> System.out.println("start");<BR> Process pr = Runtime.getRuntime().exec("python test.py");</P><P> BufferedReader in = new BufferedReader(new InputStreamReader(<BR> pr.getInputStream()));<BR> String line;<BR> while ((line = in.readLine()) != null) {<BR> System.out.println(line);<BR> }<BR> in.close();<BR> pr.waitFor();<BR> System.out.println("end");<BR> } catch (Exception e) {<BR> e.printStackTrace();<BR> }<BR> }<BR>}<BR>
如果在eclipse中直接运行报如下错误:
java.io.IOException: Cannot run program “python”: CreateProcess error=2
则配置Run Configuration中的Enviroment,增加PATH变量,见下图: