有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

运行时jar文件中未显示java Python输出

我创建了一个JavaGUI,它从用户那里获取值并将其发送到python文件进行处理,然后将python文件的输出显示到JavaGUI上。这在eclipse上工作得非常好,但是当我将其导出到jar文件中时,不会显示输出。我见过很多其他类似的问题,但它们并没有给出一个对我有帮助的解决方案

这就是我如何将python脚本连接到java的方法

public void connection(String name)
    {
        ProcessBuilder pb= new ProcessBuilder("python","recomold.py","--movie_name",name);
         ///System.out.println("running file");
         Process process = null;
        try {
            process = pb.start();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
         int err = 0;
        try {
            err = process.waitFor();
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        // System.out.println("any errors?"+(err==0 ? "no" : "yes"));
        /* try {
            System.out.println("python output "+ output(process.getInputStream()));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }*/
         try {
            matches.setText(output(process.getInputStream()));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private String output(InputStream inputStream) throws IOException {
        StringBuilder sb = new StringBuilder();
        BufferedReader br = null;
        try{
            br= new BufferedReader(new InputStreamReader(inputStream));
            String line = null;
            while((line=br.readLine())!=null)
            {
                sb.append(line+"\n");
                //descp.setText("<html><br/><html>");
                //sb.append("\n");
            }
        }
        finally
        {                   
                br.close();                 
        }
        return sb.toString();
    }

共 (0) 个答案