Java reading standard output from an external program using inputstream

前端 未结 5 1961
自闭症患者
自闭症患者 2020-12-10 20:19

I am trying to develop a class that reads the standard output of an external program(using an instance of Process, Runtime.getRuntime().exec(cmdLine, env, dir)). The program

5条回答
  •  渐次进展
    2020-12-10 20:47

    For the benefit of others looking for solutions to this type of problem I just want to add that I had a very similar problem. But in my case the program was also waiting for a single line of input. So there need to be three threads involved to asynchronously handle all three channels.

    Without writing to the output (i.e. the stdin of the executing program) caused the input (i.e. the output from the executing program) not to be captured completely. Writing to it hanged the process.

    The solution was the three words by Jon Skeet: "and flush it". After adding the flush, no hang. Thanks!

提交回复
热议问题