Wednesday, January 11, 2012

Reading Console Output


 Process p  = Runtime.getRuntime().exec(command);
     
      // Print the output. Since we read until
      // there is no more input, this causes us
      // to wait until the process is completed
      if(printResults) {
        BufferedInputStream buffer =
          new BufferedInputStream(p.getInputStream());
        DataInputStream commandResult =
          new DataInputStream(buffer);
        String s = null;
        try {
          while ((s = commandResult.readLine()) != null)
            System.out.println("Output: " + s);
          commandResult.close();
          if (p.exitValue() != 0) {
            if (verbose)
              printError(command +
                         " -- p.exitValue() != 0");
            return(false);
          }

No comments: