天天看点

java调用python脚本、import耗时_通过java调用python脚本?

我写了一个代码,通过java调用一个python脚本,我尝试过使用这两种方法运行时.exec()和process builder,但通过这两种方式,我面临着相同的问题。在

我的代码是:Process pr=Runtime.getRuntime().exec("/usr/bin/python /home/abhijeet/delete.py");

pr.waitFor();

System.out.println("----- will read ouput now -----");

BufferedReader br1=new BufferedReader(new InputStreamReader(pr.getInputStream()));

String line;

System.out.println("reached pont 1");

while ((line=br1.readLine())!=null)

{

System.out.println("inside while");

System.out.println("line--"+line);

}

System.out.println("outside while");

我添加了许多sop来了解程序的流程,但我的sop都没有被调用,可能的原因是公共服务部()保持等等,如果我删除了br1.readline()返回null和“reached point 1”和“outside while”消息印刷的。哪个意味着我的脚本没有被调用。有人能看出我做错了什么吗?在

我的python scip代码是一个交互式代码,代码:

^{pr2}$