title: Capture the output of DOS (command prompt) and display in a JAVA Frame
body: <p>When I run a python script, the output appears on the DOS ( command prompt in Windows ).</p>
  
  <p>I want the output be displayed on a JAVA Application, i.e. on a window which contians JTextArea. The output should be same as that on the DOS. </p>
  
  <p>So, <strong>How do I capture the output from the DOS and insert it into JAVA Application ??</strong></p>
  
  <p>(I tried storing output of the python script in a text file and then reading it using JAVA. But, in that case, the JAVA application waits for the script to finish running first and then displays the output. And, when the output is more than the screen size, a scroll bar appeears, so that I can see the entire output.)</p>
  
  <hr>
  
  <p>After crowder's comment, I ran this code. but the output is always:</p>
  
  <p>error:
  Process said:</p>
  
  <pre><code>import java.io.*;
  import java.lang.*;
  import java.util.*;
  class useGobbler {
          public static void main ( String args[] )
          {
          ProcessBuilder pb; 
          Process p;
          Reader r;
          StringBuilder sb;
          int ch;
  
          sb = new StringBuilder(2000);
  
          try
          {
              pb = new ProcessBuilder("python","printHello.py");
              p = pb.start();
  
              r = new InputStreamReader(p.getInputStream());
              while((ch =r.read() ) != -1)
              {
                  sb.append((char)ch);
              }
  
          }
          catch(IOException e)
          {
              System.out.println("error");
  
          }
  
          System.out.println("Process said:" + sb);
      }
  }
  </code></pre>
  
  <p>Can anyone tell me what am I doing wrong ??</p>