InteractiveExec
util.InteractiveExec

Execute a command as a separately running subprocess. <p>This actor uses java.lang.Runtime.exec() to invoke a subprocess named be the <i>command</i> parameter in a <i>directory</i> with an <i>environment</i>. Data from the <i>input</i> port (if any) is passed to the input of the subprocess. The subprocess is run until it exits and then contents of the output and error streams of the subprocess (if any) are passed to the <i>output</i> and <i>error</i> ports. <p>If the subprocess generates no data on the output or error stream, then the data on the corresponding port(s) will consist of the empty string. <p>A much more interesting actor could be written using a Kahn Process Network. This actor would generate output asynchronously as the process was executing. <p>Currently, there appears to be no way to get the subprocess to exit by passing it input. For example, if the <i>command</i> is set to the <code>cat</code> command, and we pass in a Const with the value <code>\04</code>, then the cat subprocess does <b>not</b> interpret this as the end of file marker and exit. <p>For information about Runtime.exec(), see: <a href="http://jw.itworld.com/javaworld/jw-12-2000/jw-1229-traps.html" target="_top">http://jw.itworld.com/javaworld/jw-12-2000/jw-1229-traps.html</a> and <a href="http://mindprod.com/jgloss/exec.html" target="_top">http://mindprod.com/jgloss/exec.html</a>

Author(s): Christopher Hylands Brooks, Contributor: Edward A. Lee
Version:$Id: InteractiveExec.doc.html,v 1.1 2006/02/22 18:41:22 mangal Exp $
Pt.Proposed Rating:Yellow (cxh) 2/5/04
Pt.Accepted Rating:Yellow (cxh) 2/24/04


error
Data that is generated by the subprocess on its standard error. While the process is running, any error data generated by the subprocess is stored until the subprocess exits and then the stored error data is sent to the <i>error</i> port. If the subprocess generates no data on standard error, then the empty string (a string of length zero) is generated. <p>The port is an output port of type String.
input
Strings to pass to the standard input of the subprocess. Note that a newline is not appended to the string. If you require a newline, add one using the AddSubtract actor. <p>This port is an input port of type String.
output
Data that is generated by the subprocess on standard out. While the process is running, any output data generated by the subprocess is stored until the subprocess exits and then the stored output data is sent to the <i>output</i> port. If the subprocess generates no data on standard out, then the empty string (a string of length zero) is generated. <p>The port is an output port of type String.


command
The command to be executed. The command is parsed by <a href="../ptolemy/util/StringUtilities.html#tokenizeForExec">tokenizeForExec(String)</a> into tokens and then executed as a separate subprocess. The initial default value is the string <code>echo "Hello, world."</code>. <p>The command parameter is read only once during fire(). If you want to spawn another different command, use life cycle management actors such RunCompositeActor.
directory
The directory in which to execute the command. <p> This parameter is an Expert mode parameter, so it is usually hidden. To edit it, right click on the actor, select 'Configure', then hit the 'Preferences' button and select 'Expert Mode'. <p>This parameter is read each time the subprocess is started in fire(). Once the subprocess is running, this parameter is not read again until fire() is called again. <p>The initial default value of this parameter $CWD, which corresponds with the value of the Java virtual machine user.dir property which is the user's current working directory. Note that if we are running inside a menu launched application, then ptolemy.actor.gui.jnlp.MenuApplication will change user.dir to be the value of user.home, which is the name of the user's home directory.
environment
The environment in which to execute the command. <p> This parameter is an Expert mode parameter, so it is usually hidden. To edit it, right click on the actor, select 'Configure', then hit the 'Preferences' button and select 'Expert Mode'. <p>This parameter is read each time the subprocess is started in fire(). Once the subprocess is running, this parameter is not read again until fire() is called again. <p>This parameter is an array of records that name an environment variable and the value for the value. The format is: <pre> {{name = "<i>NAME1</i>", value = "</i>value1</i>"}...} </pre> Where <code><i>NAME1</i></code> is the name of the environment variable, and <code><i>value1</i></code> is the value. <p>For example <code>{{name = "PTII", value = "c:/ptII"}}</code> would set the value of the <code>PTII</code> to <code>c:/ptII</code>. <p>If the initial value of the parameter is <code>{{name="", value = ""}}</code>, then the environment from the calling or parent process is used in the new command. <p>Note that if this parameter sets any environment variable, then under Windows the other environment variables in the calling or parent process might not be passed to the subprocess. This behaviour could be platform or JVM dependent. When in doubt, try setting the <i>command</i> value to "env" to print out the environment.