how-to

Others

How to read output from external application/process

When you run external application you can read its output (if some output for that process exists). In this example is readed installed version of Java:

try {
  /* -- start process */
  Process process = Runtime.getRuntime().exec( "java.exe -version" );
      
  /* -- wait till end */
  process.waitFor();
      
  /* -- check error stream as output */
  int i;
  while ( ( i = process.getErrorStream().read ()) != -1 ) {
    System.out.print ( (char)i );                       
  }
                        
} catch (IOException ex) {
  Logger.getLogger(Window.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
  Logger.getLogger(Window.class.getName()).log(Level.SEVERE, null, ex);
}

The output could be:

java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b11)
Java HotSpot(TM) Client VM (build 23.3-b01, mixed mode, sharing)