org.jpop.io
Class IOControl

java.lang.Object
  extended byorg.jpop.io.IOControl

public class IOControl
extends java.lang.Object

Controls the I/O for a process. When using the std[in|out|err] streams, they must all be put on different threads to avoid blocking!

Version:
1.5
Author:
dsm

Constructor Summary
IOControl(java.lang.Process process)
          Constructor for the IOControl object
 
Method Summary
 java.lang.Process getProcess()
          Gets the process attribute of the IOControl object.
 java.io.BufferedReader getStderr()
          Gets the stderr attribute of the IOControl object
 java.io.PrintStream getStdin()
          Gets the stdin attribute of the IOControl object
 java.io.BufferedReader getStdout()
          Gets the stdout attribute of the IOControl object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IOControl

public IOControl(java.lang.Process process)
Constructor for the IOControl object

Parameters:
process - The process to control I/O for
Method Detail

getStdin

public java.io.PrintStream getStdin()
Gets the stdin attribute of the IOControl object

Returns:
The stdin value

getStdout

public java.io.BufferedReader getStdout()
Gets the stdout attribute of the IOControl object

Returns:
The stdout value

getStderr

public java.io.BufferedReader getStderr()
Gets the stderr attribute of the IOControl object

Returns:
The stderr value

getProcess

public java.lang.Process getProcess()
Gets the process attribute of the IOControl object. To monitor the process (as opposed to just letting it run by itself) its necessary to create a thread like this:
. IOControl ioc;
.
. new Thread(){
.     public void run(){
.         while(true){    // only necessary if you want the process to respawn
.             try{
.                 ioc = new IOControl(Runtime.getRuntime().exec("procname"));
.                 // add some code to handle the IO streams
.                 ioc.getProcess().waitFor();
.             }catch(InterruptedException ie){
.                 // deal with exception
.             }catch(IOException ioe){
.                 // deal with exception
.             }
.
.             // a break condition can be included here to terminate the loop
.         }               // only necessary if you want the process to respawn
.     }
. }.start();
  

Returns:
The process value