public static String monitorProcessOutput(Process p,String theString){
  boolean keepReadingLines=true;
  boolean endOfLine=false;
  boolean foundIt=false;
  boolean appRunning=true;
  String ret=null;
  int readInt=-1;
  InputStream is=null;
  BufferedReader br=null;
  String line="";
  try {
    is=p.getInputStream();
    br=new BufferedReader(new InputStreamReader(is));
    while (keepReadingLines) {
      endOfLine=false;
      line="";
      while (!endOfLine) {
        if (br.ready() && (is.available() > 0)) {
          readInt=is.read();
          if (readInt == 13 || readInt == 10) {
            endOfLine=true;
          }
 else {
            line+=(char)readInt;
          }
        }
 else {
          Thread.sleep(100);
          if (!processRunning(p) && (!br.ready()) && (is.available() <= 0)) {
            endOfLine=true;
            keepReadingLines=false;
          }
 else {
          }
        }
      }
      if (line.indexOf(theString) > -1) {
        ret=line;
        foundIt=true;
        keepReadingLines=false;
      }
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
  return ret;
}

public static String monitorProcessOutput ( Process p , String theString ) { boolean keepReadingLines = true ; boolean endOfLine = false ; boolean foundIt = false ; boolean appRunning = true ; String ret = null ; int readInt = - 1 ; InputStream is = null ; BufferedReader br = null ; String line = "" ; try { is = p . getInputStream ( ) ; br = new BufferedReader ( new InputStreamReader ( is ) ) ; while ( keepReadingLines ) { endOfLine = false ; line = "" ; while ( ! endOfLine ) { if ( br . ready ( ) && ( is . available ( ) > 0 ) ) { readInt = is . read ( ) ; if ( readInt == 13 || readInt == 10 ) { endOfLine = true ; } else { line += ( char ) readInt ; } } else { Thread . sleep ( 100 ) ; if ( ! processRunning ( p ) && ( ! br . ready ( ) ) && ( is . available ( ) <= 0 ) ) { endOfLine = true ; keepReadingLines = false ; } else { } } } if ( line . indexOf ( theString ) > - 1 ) { ret = line ; foundIt = true ; keepReadingLines = false ; } } } catch ( Exception e ) { e . printStackTrace ( ) ; } return ret ; }
given a process and a string , monitors the output of the process for the string . returns the line in which the string is found , or null if not found . it will continue until the process exits .
