Python输出未显示在jar文件中

时间:2019-06-24 08:20:28

标签: java python

我创建了一个Java gui,它将用户的值发送到python文件进行处理,然后将python文件的输出显示到java gui上。这在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 个答案:

没有答案