Java.lang.ProcessBuilder.redirectErrorStream() Method



Description

The java.lang.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

Example

The following example shows the usage of lang.ProcessBuilder.redirectErrorStream() method.

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());
   }
}

Let us compile and run the above program, this will produce the following result −

true
java_lang_processbuilder.htm
Advertisements