Home » Java programming language

Java ProcessBuilder redirectErrorStream() method with example

ProcessBuilder Class redirectErrorStream() method: Here, we are going to learn about the redirectErrorStream() method of ProcessBuilder Class with its syntax and example.
Submitted by Preeti Jain, on December 13, 2019


    public boolean  redirectErrorStream ();
    public ProcessBuilder  redirectErrorStream (boolean re_err_stm);

ProcessBuilder Class redirectErrorStream() method

  • redirectErrorStream() method is available in java.lang package.
  • redirectErrorStream () method is used to check whether this process builder combines standard error and standard output.
  • redirectErrorStream (boolean re_err_stm) method is used to puts the redirectErrorStream property of this process builder.
  • These methods don't throw an exception at the time of combining error and output stream.
  • These are non-static methods, it is accessible with the class object only and, if we try to access these methods with the class name then we will get an error.


  • In the first case, it does not accept any parameter.
  • In the second case, Boolean re_err_stm - This parameter represents the new property.

Return value:

In the first case, the return type of the method is boolean – It returns true then error output will be combined with the standard output so that by using the getInputStream() method of Process class can be read both error and output otherwise it returns false.

In the second case, the return type of the method is ProcessBuilder, it returns this process builder.


// Java program to demonstrate the example 
// of redirectErrorStream() method of ProcessBuilder class

import java.util.*;

public class RedirectErrorStream {
    public static void main(String[] args) throws Exception {
        // Creating an object of List
        List l = new LinkedList();

        // By using add() method to add elements

        // Instantiating ProcessBuilder object
        ProcessBuilder pr_bu = new ProcessBuilder(l);

        // By using redirectErrorStream() method is 
        // to check whether this error stream is redirected
        // or not
        System.out.println("pr_bu.redirectErrorStream() =" + pr_bu.redirectErrorStream());

        // By using redirectErrorStream(boolean re_err_stm) method is not to 
        // redirect the error stream
        System.out.println("pr_bu.redirectErrorStream(false) =" + pr_bu.redirectErrorStream());

        // By using redirectErrorStream(boolean re_err_stm) //method is to 
        // redirect the error stream
        System.out.println("pr_bu.redirectErrorStream(true) =" + pr_bu.redirectErrorStream());


pr_bu.redirectErrorStream() =false
pr_bu.redirectErrorStream(false) =false
pr_bu.redirectErrorStream(true) =true


Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.