// $Id: ProcessOutput.java,v 1.1 2004/02/25 17:29:18 cadlerun Exp $
// ProcessOutput.java -- 
// Author: Aaron Adler <cadlerun@fracas.ai.mit.edu> 
// Copyright: Copyright (C) 2002 by Aaron Adler 
// Created: <Tue Feb 24 14:11:49 2004> 

package rec.multi;

import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * A simple class that outputs the printlns from a given process. Used
 * to see the output from the speech process that is connected via
 * RMI.
 **/
public class ProcessOutput implements Runnable {

  private Process m_process;
  private boolean m_done = false;
  
  public ProcessOutput(Process p) {
    m_process = p;
  }

  public void run() {
    try {
      BufferedReader stdInput = new BufferedReader(new InputStreamReader(m_process.getInputStream()));
      BufferedReader stdError = new BufferedReader(new InputStreamReader(m_process.getErrorStream()));
      String s = null;
      while (!m_done) {
	while ((s = stdInput.readLine()) != null) {
	  System.out.println("!from outside process: ["+s+"]");
	}
	while ((s = stdError.readLine()) != null) {
	  System.out.println("!error outside process class: ["+s+"]");
	}
      }
    } catch (IOException e) {
      System.out.println("an error occured while trying to output text from a process: "+e);
    }
  }
  
  /**
   * Stop trying to print stuff
   */
  public void stop() {
    m_done = true;
  }

}
