Java reading standard output from an external program using inputstream

前端 未结 5 1954
自闭症患者
自闭症患者 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 21:03

    You have to consume both the program's stdout and stderr concurrently to avoid blocking scenarios.

    See this article for more info, and in particular note the StreamGobbler mechanism that captures stdout/err in separate threads. This is essential to prevent blocking and is the source of numerous errors if you don't do it properly!

提交回复
热议问题