How to run a python script from java?

前端 未结 3 2160
长情又很酷
长情又很酷 2020-12-10 08:44

I have this java application and ran into a requirement to parse an STDF.

Actually all I needed is to get the FAR,MIR and MRR sections of an stdf file. There exists

相关标签:
3条回答
  • 2020-12-10 09:04

    Try creating a cmd file and then call that using Java.

    0 讨论(0)
  • 2020-12-10 09:07

    You should perhaps call p.waitFor(); so that your Java program doesn't move on until after the external process has finished executing.

    Update 1: Also make sure you are reading all the bytes out of p.getErrorStream() and p.getInputStream(). Failure to do so may hang the process.

    Update 2: You may also want to check the process return code for an error code. The process return code is accessed via waitFor()'s return value.

    0 讨论(0)
  • 2020-12-10 09:14

    In addition to making sure you call p.waitFor(), you may also have to read the contents of the streams. If the streams aren't read, the processes will stall.

    Try adding this class: http://www.physionet.org/physiotools/puka/sourceCode/puka/StreamGobbler.java

    And calling it:

     new StreamGobbler(p.getErrorStream(), "Error");
     new StreamGobbler(p.getInputStream(), "Input");
    

    You might be able to come up with a more efficient class on your own, but that one should at least give you the basic idea (note that it wasn't written by me).

    0 讨论(0)
提交回复
热议问题