Capturing stdout when calling Runtime.exec

后端 未结 8 1204
终归单人心
终归单人心 2020-11-21 23:26

When experiencing networking problems on client machines, I\'d like to be able to run a few command lines and email the results of them to myself.

I\'ve found Runtim

8条回答
  •  臣服心动
    2020-11-22 00:00

    You need to capture both the std out and std err in the process. You can then write std out to a file/mail or similar.

    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!

提交回复
热议问题