tcl.lang
Class Pipeline

java.lang.Object
  extended by tcl.lang.Pipeline
All Implemented Interfaces:
Runnable

public class Pipeline
extends Object
implements Runnable

This class encapsulates a pipeline of operating system commands


Constructor Summary
Pipeline(Interp interp, TclObject[] objv, int startIndex)
          Create a Pipeline initialized with commands.
 
Method Summary
 int addCommand(List<String> command, File workingDir)
          Add an operating system command to the end of the pipeline
 void exec()
          Executes the pipeline.
 int[] getExitValues()
           
 int[] getProcessIdentifiers()
           
 Redirect getStderrRedirect()
           
 Redirect getStdinRedirect()
           
 Redirect getStdoutRedirect()
           
 boolean isErrorRedirectedToResult()
          Return true if 2>@1 was seen
 boolean isExecInBackground()
           
 void run()
           
 void setExecInBackground(boolean execInBackground)
           
 void setStderrRedirect(Redirect stderrRedirect)
           
 void setStdinRedirect(Redirect stdinRedirect)
           
 void setStdoutRedirect(Redirect stdoutRedirect)
           
 void throwAnyExceptions()
           
 void waitForExitAndCleanup(boolean force)
          Wait for processes in pipeline to die, then close couplers and any open channels
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Pipeline

public Pipeline(Interp interp,
                TclObject[] objv,
                int startIndex)
         throws TclException
Create a Pipeline initialized with commands.

Parameters:
interp - TCL interpreter for this Pipeline
objv - Array of TclObjects that are in the for of TCL's 'exec' args
startIndex - index of the objv object at which to start parsing
Throws:
TclException - if a syntax error occurs
Method Detail

addCommand

public int addCommand(List<String> command,
                      File workingDir)
               throws TclException
Add an operating system command to the end of the pipeline

Parameters:
command - The command and its arguments. The List is not copied, so any changes will be reflected in the Pipeline
workingDir - New command starts in this directory
Returns:
index of the new command in the pipeline
Throws:
TclException

exec

public void exec()
          throws TclException
Executes the pipeline. If the execInBackground property is false, exec() waits for processes to complete before returning. If any input and output channels (pipeline*Channel) have not been set either in the constructor with the TCL redirection operator, or with setPipeline*Channel(), data will be read/written from System.in, System.out, System.err.

Throws:
TclException

waitForExitAndCleanup

public void waitForExitAndCleanup(boolean force)
                           throws TclException
Wait for processes in pipeline to die, then close couplers and any open channels

Parameters:
force - Kill processes forcibly, if true
Throws:
TclException

getStdinRedirect

public Redirect getStdinRedirect()
Returns:
the stdinRedirect

setStdinRedirect

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

getStdoutRedirect

public Redirect getStdoutRedirect()
Returns:
the stdoutRedirect

setStdoutRedirect

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

getStderrRedirect

public Redirect getStderrRedirect()
Returns:
the stderrRedirect

setStderrRedirect

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

isExecInBackground

public boolean isExecInBackground()
Returns:
the execInBackground property

setExecInBackground

public void setExecInBackground(boolean execInBackground)
Parameters:
execInBackground - Set the execInBackground property, which determines if the Pipeline runs in the background

isErrorRedirectedToResult

public boolean isErrorRedirectedToResult()
Return true if 2>@1 was seen


getProcessIdentifiers

public int[] getProcessIdentifiers()
Returns:
Array of process identifiers, or array of -1 if we can't get PIDs

getExitValues

public int[] getExitValues()
Returns:
Exit values of all processes in the pipeline; only valid if processes have exited

throwAnyExceptions

public void throwAnyExceptions()
                        throws TclException
Throws:
IOException - if one has been caught during a background waitForExitAndCleanup
TclException

run

public void run()
Specified by:
run in interface Runnable


Copyright © 2015. All rights reserved.