There are many topics around the ProcessBuilder. The focus here is how to handle the output of executed commands correctly!
The following two things are important:
- Consuming STDOUT and STDERR is necessary to avoid freezing!
- If the process writes a large amount of output, it must be consumed. This can be done by calling ProcessBuilder#redirectErrorStream, which redirects STDERR to STDOUT!
I've written a wrapper object to the ProcessBuilder to handle and configure it easier. Have look at the code below.
Here is a simple example to demonstrate the usage: