I am looking for a way to redirect the output of a Process / ProcessBuilder? I know that it works in Java 7 like this:
ProcessBuilder builder = new ProcessBuilder(command);
builder.redirectOutput();
Process process = builder.start();
But I need the same for Java 5/6 ... Any help highly appreciated.
Sample code for cmd process on Windows 7, working with Java 6:
ProcessBuilder processBuilder = new ProcessBuilder( "cmd" );
Process process = processBuilder.start();
OutputStream stream = process.getOutputStream();
Javadoc for getOutputStream()
method: says
"Gets the output stream of the subprocess. Output to the stream is piped into the standard input stream of the process represented by this Process object."
To redirect the output of a process, I think you can use stream
object defined in the code above. You can write it to console etc.
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