tcl.lang.process
Class TclProcess

java.lang.Object
  extended by tcl.lang.process.TclProcess
Direct Known Subclasses:
JavaProcess

public abstract class TclProcess
extends Object

This abstract class represents a process that may be executed from Tcl. Individual platforms should create a subclass of TclProcess, which is instantiated with with TclProcess.newInstance(). This class is somewhat of a combination of java.lang.ProcessBuilder and java.lang.Process, with inspiration from the Java 1.7 API. It is provided to allow for better native process control than Java's APIs.

Author:
Dan Bodoh

Field Summary
protected  List<String> command
          The command words that will be executed
protected  Interp interp
          The current interpreter
protected  IOException savedException
          An exception to be thrown in the main thread, but caught in any child thread
protected  Redirect stderrRedirect
          A tcl.lang.process.Redirect object specifying where stderr is redirected to
protected  Redirect stdinRedirect
          A tcl.lang.process.Redirect object specifying where stdin is redirected from
protected  Redirect stdoutRedirect
          A tcl.lang.process.Redirect object specifying where stdout is redirected to
 
Constructor Summary
TclProcess()
           
 
Method Summary
abstract  boolean canInheritFileDescriptors()
           
 List<String> command()
           
abstract  void destroy()
          Kill the running process
abstract  int exitValue()
           
protected  Map<String,String> getenv()
           
abstract  int getPid()
           
 Redirect getStderrRedirect()
           
 Redirect getStdinRedirect()
           
 Redirect getStdoutRedirect()
           
protected abstract  int implWaitFor()
          Platform-specific wait for the process to complete
abstract  boolean isStarted()
           
static TclProcess newInstance(Interp interp)
          Create a new platform-specific instance of a TclProcess subclass.
protected  void saveIOException(IOException e)
           
 void setCommand(List<String> command)
          Set the command words to be executed
 void setStderrRedirect(Redirect stderrRedirect)
           
 void setStdinRedirect(Redirect stdinRedirect)
           
 void setStdoutRedirect(Redirect stdoutRedirect)
           
abstract  void setWorkingDir(File workingDir)
           
abstract  void start()
          Start the process executing, and register streams with any STREAM redirects
protected  void throwAnyExceptions()
           
 int waitFor()
          Wait for the process to complete
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stdinRedirect

protected Redirect stdinRedirect
A tcl.lang.process.Redirect object specifying where stdin is redirected from


stdoutRedirect

protected Redirect stdoutRedirect
A tcl.lang.process.Redirect object specifying where stdout is redirected to


stderrRedirect

protected Redirect stderrRedirect
A tcl.lang.process.Redirect object specifying where stderr is redirected to


command

protected List<String> command
The command words that will be executed


interp

protected Interp interp
The current interpreter


savedException

protected IOException savedException
An exception to be thrown in the main thread, but caught in any child thread

Constructor Detail

TclProcess

public TclProcess()
Method Detail

newInstance

public static TclProcess newInstance(Interp interp)
Create a new platform-specific instance of a TclProcess subclass. This method detects the current platform and returns an instance of the appropriate TclProcess subclass.

Parameters:
interp - The current interpreter
Returns:
A platform-specific TclProcess subclass instance

setCommand

public void setCommand(List<String> command)
Set the command words to be executed

Parameters:
command - Command words to be executed

command

public List<String> command()
Returns:
The command words to be executed

getenv

protected Map<String,String> getenv()
Returns:
a unmodifiable Map containing the environment that the subprocess should inherit. System.getenv() is not sufficient because JTcl cannot update it on env() array changes.

start

public abstract void start()
                    throws IOException
Start the process executing, and register streams with any STREAM redirects

Throws:
IOException

exitValue

public abstract int exitValue()
                       throws IllegalThreadStateException
Returns:
The process's exit value
Throws:
IllegalThreadStateException - if the process has not yet completed

waitFor

public int waitFor()
            throws IllegalThreadStateException,
                   InterruptedException,
                   IOException
Wait for the process to complete

Returns:
this process's exit value
Throws:
IllegalThreadStateException - if the process has not yet been started
InterruptedException - if the process is interrupted
IOException

implWaitFor

protected abstract int implWaitFor()
                            throws InterruptedException,
                                   IOException
Platform-specific wait for the process to complete

Returns:
this process's exit value
Throws:
InterruptedException - if the process is interrupted
IOException

getPid

public abstract int getPid()
                    throws IllegalThreadStateException
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 abstract boolean isStarted()
Returns:
true if the process has started; false otherwise

setWorkingDir

public abstract void setWorkingDir(File workingDir)
Parameters:
workingDir - Directory the process starts in

destroy

public abstract void destroy()
Kill the running process


canInheritFileDescriptors

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

getStdinRedirect

public Redirect getStdinRedirect()
Returns:
the stdinRedirect

saveIOException

protected void saveIOException(IOException e)
Parameters:
e - Exception to throw later in the main thread

throwAnyExceptions

protected void throwAnyExceptions()
                           throws IOException
Throws:
Exception - if any exception was passed to saveException()
IOException

setStdinRedirect

public void setStdinRedirect(Redirect stdinRedirect)
                      throws TclException
Parameters:
stdinRedirect - the stdinRedirect to set
Throws:
TclException

getStdoutRedirect

public Redirect getStdoutRedirect()
Returns:
the stdoutRedirect

setStdoutRedirect

public void setStdoutRedirect(Redirect stdoutRedirect)
                       throws TclException
Parameters:
stdoutRedirect - the stdoutRedirect to set
Throws:
TclException

getStderrRedirect

public Redirect getStderrRedirect()
Returns:
the stderrRedirect

setStderrRedirect

public void setStderrRedirect(Redirect stderrRedirect)
                       throws TclException
Parameters:
stderrRedirect - the stderrRedirect to set
Throws:
TclException


Copyright © 2015. All rights reserved.