Home » 
        Java programming language
    
    Java Process getErrorStream() method with example
    
    
    
            
        Process Class getErrorStream() method: Here, we are going to learn about the getErrorStream() method of Process Class with its syntax and example.
        Submitted by Preeti Jain, on December 10, 2019
    
    
    Process Class getErrorStream() method
    
        - getErrorStream() method is available in java.lang package.
- getErrorStream() method is used to get the error stream of the processes or subprocess.
- getErrorStream() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
- getErrorStream() method does not throw an exception at the time of returning input stream.
Syntax:
    public abstract InputStream getErrorStream();
    Parameter(s):
    
        - It does not accept any parameter.
Return value:
    The return type of this method is InputStream, it returns InputStream associated to the error stream of the process and subprocess.
    Example:
// Java program to demonstrate the example 
// of InputStream getErrorStream() method 
// of Process 
import java.io.*;
import java.util.*;
public class GetErrorStream {
    public static void main(String[] args) throws Exception {
        // Instantiating Process object
        System.out.println("Process Instantiated");
        Process pr = Runtime.getRuntime().exec("notepad.exe");
        // By using errorStream() method is to get the 
        // error stream of pr object
        InputStream is = pr.getErrorStream();
        // Read from InputStream
        for (int k = 0; k < is.available(); ++k)
            System.out.println("Error stream = " + is.read());
        // Destroy a process
        pr.destroy();
        System.out.println("Process Destroyed");
    }
}
Output
Process Instantiated
Process Destroyed
    
    
  
    Advertisement
    
    
    
  
  
    Advertisement