Capturing stdout when calling Runtime.exec

后端 未结 8 1181
终归单人心
终归单人心 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-21 23:46

    Use ProcessBuilder. After calling start() you'll get a Process object from which you can get the stderr and stdout streams.

    UPDATE: ProcessBuilder gives you more control; You don't have to use it but I find it easier in the long run. Especially the ability to redirect stderr to stdout which means you only have to suck down one stream.

提交回复
热议问题