抠脚Q太郎 2019-05-30 17:34 采纳率: 0%
浏览 1368

Java 【Runtime.getRuntime().exec()】调用python脚本(含第三方库)问题

写好的java代码 通过cmd javac编译后可以执行并且成功调用第三方库wordcloud 生成了结果图片。

但是同样的代码放在eclipse中运行就不行。

cmd成功运行:

图片说明

eclipse运行失败
图片说明

java代码

public class JavaUsePython3libByRuntime{
        public static void main(String[] args) throws IOException, InterruptedException {
            System.out.println("start");
            String[] args1=new String[]{"d:\\Python\\python.exe","C:\\Users\\LJL\\Desktop\\source\\python\\tfidfgenerate.py"};
            Process pr=Runtime.getRuntime().exec(args1);

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

            String line = null;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
            in.close();

            int re = pr.waitFor();

            System.out.println("End:return   "+re);
        }
    }



  • 写回答

1条回答 默认 最新

报告相同问题?