title: Java reading standard output from an external program using inputstream
body: <p>I am trying to develop a class that reads the standard output of an external program(using an instance of Process, Runtime.getRuntime().exec(cmdLine, env, dir)).
  The program takes user inputs during the process, and would not proceed until a valid input is given; this seems to be causing a problem in the way I am trying to read its output:</p>
  
  <pre><code>    egm.execute(); // run external the program with specified arguments
      BufferedInputStream stdout = new BufferedInputStream(egm.getInputStream());
      BufferedInputStream stderr = new BufferedInputStream(egm.getErrorStream());
      BufferedOutputStream stdin = new BufferedOutputStream(egm.getOutputStream());
  
  
  
      int c; //standard output input stream
      int e; //standadr error input stream
  
      while((c=stdout.read()) != -1) //&lt;-- the Java class stops here, waiting for input? 
      {
          egm.processStdOutStream((char)c); 
      }
      while((e=stderr.read()) != -1)
      {
          egm.processStdErrStream((char)e);
      }
      //...
  </code></pre>
  
  <p>How can I fix this so that the program takes in a valid input and proceed? Any help resolving this problem will be great!</p>