I want to join stderr (getErrorStream
) and stdout (getInputStream
) of a Process
into a single Stream
to be consumed elsewhere. Is there anything in Java's library that will do that for me?
Note: no external libraries. I'm not interested in the existence of a solution provided by, say, Apache Commons IO. I only want to know if there's something that comes with JDK.
ProcessBuilder.redirectErrorStream(boolean)
does what you want.
public ProcessBuilder redirectErrorStream(boolean redirectErrorStream)
Sets this process builder's
redirectErrorStream
property.If this property is
true
, then any error output generated by subprocesses subsequently started by this object'sstart()
method will be merged with the standard output, so that both can be read using theProcess.getInputStream()
method. This makes it easier to correlate error messages with the corresponding output. The initial value isfalse
.
EDIT: @Since Java 5 or later so should be widely available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With