Capturing stdout when calling Runtime.exec

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.

Leave a Comment