- Java.lang Package classes
- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package extras
- Java.lang - Interfaces
- Java.lang - Errors
- Java.lang - Exceptions
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
Java ProcessBuilder redirectErrorStream() Method
Description
The Java ProcessBuilder redirectErrorStream(boolean redirectErrorStream) method sets this process builder's redirectErrorStream property. If this property is true, then any error output generated by subprocesses subsequently started by this object's start() method will be merged with the standard output, so that both can be read using the Process.getInputStream() method. This makes it easier to correlate error messages with the corresponding output. The initial value is false.
Declaration
Following is the declaration for java.lang.ProcessBuilder.redirectErrorStream() method
public ProcessBuilder redirectErrorStream(boolean redirectErrorStream)
Parameters
redirectErrorStream − The new property value
Return Value
This method returns this process builder
Exception
NA
Setting redirect error stream for Notepad using a Process Builder Example
The following example shows the usage of ProcessBuilder redirectErrorStream() method. In this program, we've created an array of Strings and added notepad.exe and test.txt to it. Using that list, we've initialized a ProcessBuilder instance. Now using redirectErrorStream() method, we've set the redirect error stream flag and then retrieved the redirect error stream and printed a corresponding mapped flag.
package com.tutorialspoint; public class ProcessBuilderDemo { public static void main(String[] args) { // create a new list of arguments for our process String[] list = {"notepad.exe", "test.txt"}; // create the process builder ProcessBuilder pb = new ProcessBuilder(list); // Redirect the errorstream pb.redirectErrorStream(true); System.out.println(pb.redirectErrorStream()); } }
Output
Let us compile and run the above program, this will produce the following result −
true
Setting redirect error stream for Calculator using a Process Builder Example
The following example shows the usage of ProcessBuilder redirectErrorStream() method. In this program, we've created an array of Strings and added calc.exe to it. Using that list, we've initialized a ProcessBuilder instance. Now using redirectErrorStream() method, we've set the redirect error stream flag and then retrieved the redirect error stream and printed a corresponding mapped flag.
package com.tutorialspoint; public class ProcessBuilderDemo { public static void main(String[] args) { // create a new list of arguments for our process String[] list = {"calc.exe"}; // create the process builder ProcessBuilder pb = new ProcessBuilder(list); // Redirect the errorstream pb.redirectErrorStream(true); System.out.println(pb.redirectErrorStream()); } }
Output
Let us compile and run the above program, this will produce the following result −
true
Setting redirect error stream for Windows Explorer using a Process Builder Example
The following example shows the usage of ProcessBuilder redirectErrorStream() method. In this program, we've created an array of Strings and added explorer.exe to it. Using that list, we've initialized a ProcessBuilder instance. Now using redirectErrorStream() method, we've set the redirect error stream flag and then retrieved the redirect error stream and printed a corresponding mapped flag.
package com.tutorialspoint; public class ProcessBuilderDemo { public static void main(String[] args) { // create a new list of arguments for our process String[] list = {"explorer.exe"}; // create the process builder ProcessBuilder pb = new ProcessBuilder(list); // Redirect the errorstream pb.redirectErrorStream(true); System.out.println(pb.redirectErrorStream()); } }
Output
Let us compile and run the above program, this will produce the following result −
true