tcl.lang.process
Class JavaProcess

java.lang.Object
  extended by tcl.lang.process.TclProcess
      extended by tcl.lang.process.JavaProcess

public class JavaProcess
extends TclProcess

Implements a pure Java process. Combines java.lang.ProcessBuilder and java.lang.Process. Has the disadvantage of possibly sucking up too much stdin, and cannot outlive the JVM if it has any PIPE or CHANNEL or INHERIT redirects. When Java 1.7 is available, this class should be re-written to do a proper INHERIT redirect, instead of using the pipe model of Java 1.5, to avoid sucking up too much stdin.

Author:
danb

Field Summary
protected  Process process
          The Java Process object
protected  ProcessBuilder processBuilder
          The Java ProcessBuilder object
protected  tcl.lang.process.JavaProcess.Coupler stderrCoupler
          Coupler that reads this process's stderr
protected  OutputStream stderrStream
          The sink for this process's stderr
protected  InputStream stdinStream
          The source of bytes for this process's stdin
protected  tcl.lang.process.JavaProcess.Coupler stdoutCoupler
          Coupler that reads this process's stdout
protected  OutputStream stdoutStream
          The sink for this process's stdout
 
Fields inherited from class tcl.lang.process.TclProcess
command, interp, savedException, stderrRedirect, stdinRedirect, stdoutRedirect
 
Constructor Summary
JavaProcess()
           
 
Method Summary
 boolean canInheritFileDescriptors()
           
 void destroy()
          Kill the running process
 int exitValue()
           
 InputStream getErrorStream()
           
 InputStream getInputStream()
           
 OutputStream getOutputStream()
           
 int getPid()
           
protected  int implWaitFor()
          Platform-specific wait for the process to complete
 boolean isStarted()
           
 void setWorkingDir(File workingDir)
           
 void start()
          Start the process executing, and register streams with any STREAM redirects
 
Methods inherited from class tcl.lang.process.TclProcess
command, getenv, getStderrRedirect, getStdinRedirect, getStdoutRedirect, newInstance, saveIOException, setCommand, setStderrRedirect, setStdinRedirect, setStdoutRedirect, throwAnyExceptions, waitFor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

process

protected Process process
The Java Process object


processBuilder

protected ProcessBuilder processBuilder
The Java ProcessBuilder object


stdinStream

protected InputStream stdinStream
The source of bytes for this process's stdin


stdoutStream

protected OutputStream stdoutStream
The sink for this process's stdout


stderrStream

protected OutputStream stderrStream
The sink for this process's stderr


stdoutCoupler

protected tcl.lang.process.JavaProcess.Coupler stdoutCoupler
Coupler that reads this process's stdout


stderrCoupler

protected tcl.lang.process.JavaProcess.Coupler stderrCoupler
Coupler that reads this process's stderr

Constructor Detail

JavaProcess

public JavaProcess()
Method Detail

getOutputStream

public OutputStream getOutputStream()
Returns:
this process's stream to write stdin data to

getInputStream

public InputStream getInputStream()
Returns:
this process's stream to read stdout from

getErrorStream

public InputStream getErrorStream()
Returns:
this process's stream to read stderr from

exitValue

public int exitValue()
              throws IllegalThreadStateException
Specified by:
exitValue in class TclProcess
Returns:
The process's exit value
Throws:
IllegalThreadStateException - if the process has not yet completed

start

public void start()
           throws IOException
Description copied from class: TclProcess
Start the process executing, and register streams with any STREAM redirects

Specified by:
start in class TclProcess
Throws:
IOException

implWaitFor

protected int implWaitFor()
                   throws InterruptedException,
                          IOException
Description copied from class: TclProcess
Platform-specific wait for the process to complete

Specified by:
implWaitFor in class TclProcess
Returns:
this process's exit value
Throws:
InterruptedException - if the process is interrupted
IOException

getPid

public int getPid()
           throws IllegalThreadStateException
Specified by:
getPid in class TclProcess
Returns:
The process identifier of this process, or -1 if it cannot be determined
Throws:
IllegalThreadStateException - if the process has not yet started

isStarted

public boolean isStarted()
Specified by:
isStarted in class TclProcess
Returns:
true if the process has started; false otherwise

setWorkingDir

public void setWorkingDir(File workingDir)
Specified by:
setWorkingDir in class TclProcess
Parameters:
workingDir - Directory the process starts in

destroy

public void destroy()
Description copied from class: TclProcess
Kill the running process

Specified by:
destroy in class TclProcess

canInheritFileDescriptors

public boolean canInheritFileDescriptors()
Specified by:
canInheritFileDescriptors in class TclProcess
Returns:
true if the this TclProcess subclass can actually inherit the open file descriptors, or false if it emulates inheritance


Copyright © 2015. All rights reserved.