title: How to get live java output from console application
body: <p>I run code attached below but it gives output only after the command has completed in the <strong>String response</strong>. I want the console window activated during the running of command and get output of the command.</p>
  
  <pre class="lang-java prettyprint-override"><code>String command = "src\\youtube-dl"
                  + " --max-downloads " + maxdown.getText()
                  + " --retries " + noofretry.getText()
                  + " --write-all-thumbnails" + sub.getText() 
                  + " " + url.getText();
  
  String response = "";
  try {   
    Process p = Runtime.getRuntime().exec(command);
    InputStream in = p.getInputStream();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
  
    int c = -1;
    while((c = in.read()) != -1) {
      baos.write(c);
      System.out.flush();
      response = response + new String(baos.toByteArray());
      System.out.println(response);
    }         
  
  } catch (Exception e) {
    e.printStackTrace();
  }
  </code></pre>