pj
Class SubProcess

java.lang.Object
  extended by pj.SubProcess
Direct Known Subclasses:
Javac

public class SubProcess
extends Object

arranges to store text and process it through a native subprocess.


Nested Class Summary
static class SubProcess.Copy
          daemon thread to copy a stream to and from the subprocess.
 
Field Summary
protected  boolean delete
          true if sourceFile is a temporary file to be deleted during execute(java.lang.String[], int, java.lang.Object, pj.SubProcess.Copy, pj.SubProcess.Copy).
protected  PrintWriter source
          output to sourceFile.
protected  File sourceFile
          file for subprocess source.
 
Constructor Summary
SubProcess()
          use a temporary sourceFile without a suffix.
SubProcess(File sourceFile)
          use a named sourceFile or none.
SubProcess(String suffix)
          use a temporary sourceFile.
SubProcess(String prefix, String suffix)
          use a temporary sourceFile.
 
Method Summary
 int execute(String[] argv, int pos, Object in, SubProcess.Copy out, SubProcess.Copy err)
          execute subprocess.
 PrintWriter source()
          access to sourceFile if any.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sourceFile

protected File sourceFile
file for subprocess source.


delete

protected boolean delete
true if sourceFile is a temporary file to be deleted during execute(java.lang.String[], int, java.lang.Object, pj.SubProcess.Copy, pj.SubProcess.Copy).


source

protected PrintWriter source
output to sourceFile.

Constructor Detail

SubProcess

public SubProcess()
           throws IOException
use a temporary sourceFile without a suffix.

Throws:
IOException

SubProcess

public SubProcess(String suffix)
           throws IOException
use a temporary sourceFile.

Parameters:
suffix - for the temporary file.
Throws:
IOException

SubProcess

public SubProcess(String prefix,
                  String suffix)
           throws IOException
use a temporary sourceFile.

Parameters:
prefix - for the temporary file, 3 characters or more.
Throws:
IOException

SubProcess

public SubProcess(File sourceFile)
           throws IOException
use a named sourceFile or none.

Throws:
IOException
Method Detail

source

public PrintWriter source()
access to sourceFile if any. This can only be used until execute(java.lang.String[], int, java.lang.Object, pj.SubProcess.Copy, pj.SubProcess.Copy) is called.


execute

public int execute(String[] argv,
                   int pos,
                   Object in,
                   SubProcess.Copy out,
                   SubProcess.Copy err)
            throws InterruptedException,
                   IOException
execute subprocess.

Parameters:
argv - tokens of command line.
pos - if positive, sourceFile will be set at this position of argv; if it is zero and in is null, sourceFile is standard input for subprocess; otherwise sourceFile (if any) is ignored.
in - standard input for subprocess, or null; this can be a Reader or a InputStream.
out - copies standard output for subprocess, or null.
err - copies diagnostic output for subprocess, or null.
Returns:
exit code of subprocess.
Throws:
InterruptedException
IOException