Java Process can't get ErrorStream message
<p>everyone, I have a process that needs to get standard output and log/error/exception output from the subprocess. The standard output is fine, but I can't get ErrorStream, therefore the program is stuck there because of that. Here is my simple code. There is nothing magic, but why can't I get the error stream here? Thanks for looking at it.</p>

<pre><code>    BufferedReader standard =
         new BufferedReader(new InputStreamReader(process.getInputStream()));

   BufferedReader error = 
   new BufferedReader(new InputStreamReader(process.getErrorStream()));

    String line = null;
    while ((line = standard.readLine()) != null) {            
        System.out.println(line);
    }
    while ((line = error.readLine()) != null) {           
        System.out.println(line);
    }
</code></pre>

<p>Now, as suggested, i used two threads to process the output and error streams, but still had the same problem, as follows. Can anybody give me some insights? Thanks.</p>

<pre><code>    ProcessBuilder pb = new ProcessBuilder(listArgs);
    pb.redirectErrorStream();
    Process process = pb.start();

    StreamThread output = new StreamThread(process.getInputStream());
    StreamThread error = new StreamThread(process.getErrorStream());

    output.start();
    error.start();
    while (true) {
        try {
            output.join();
            break;
        }
        catch (InterruptedException ie) {
            ie.printStackTrace();
        }
    }
</code></pre>

<p>The definition of the StreamThread:</p>

<pre><code>    public static class StreamThread extends Thread{
    private InputStream input = null;   
    public StreamThread(InputStream in){
        input = in;
    }       
    String line = null;
    public void start(){            
        BufferedReader reader = new BufferedReader(new InputStreamReader(input));           
        try{
            while( (line=reader.readLine()) != null ){
                System.out.println(line);
            }
            reader.close();
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
</code></pre>
