|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.util.StreamExec
public class StreamExec
Execute commands in a subprocess and send the results to stderr and stdout.
As an alternative to this class, see
JTextAreaExec
, which uses Swing; and
StringBufferExec
, which writes to a StringBuffer.
Sample usage:
List execCommands = new LinkedList(); execCommands.add("date"); execCommands.add("sleep 3"); execCommands.add("date"); execCommands.add("notACommand"); final StreamExec exec = new StreamExec(); exec.setCommands(execCommands); exec.start();
Loosely based on Example1.java from http://java.sun.com/products/jfc/tsc/articles/threads/threads2.html
See also http://developer.java.sun.com/developer/qow/archive/135/index.jsp and http://jw.itworld.com/javaworld/jw-12-2000/jw-1229-traps.html
JTextAreaExec
,
StringBufferExec
Red (cxh) |
Red (cxh) |
Nested Class Summary | |
---|---|
private static class |
StreamExec._StreamReaderThread
Private class that reads a stream in a thread and updates the the StreamExec. |
Field Summary | |
---|---|
private java.util.List |
_commands
The list of command to be executed. |
private boolean |
_debug
|
private java.lang.String[] |
_envp
The environment, which is an array of Strings of the form name=value . |
private java.lang.Process |
_process
The Process that we are running. |
private int |
_subprocessReturnCode
The return code of the last Runtime.exec() command. |
private java.io.File |
_workingDirectory
The working directory of the subprocess. |
Constructor Summary | |
---|---|
StreamExec()
Create a StreamExec. |
Method Summary | |
---|---|
private java.lang.String |
_executeCommands()
Execute the commands in the list. |
protected void |
_setProgressBarMaximum(int size)
Set the maximum of the progress bar. |
private void |
_updateProgressBar(int i)
Update the progress bar. |
void |
appendToPath(java.lang.String directoryName)
Append to the path of the subprocess. |
void |
cancel()
Cancel any running commands. |
void |
clear()
Clear the text area, status bar and progress bar. |
java.lang.String |
getenv(java.lang.String key)
Get the value of the environment of the subprocess. |
int |
getLastSubprocessReturnCode()
Return the return code of the last subprocess that was executed. |
void |
setCommands(java.util.List commands)
Set the list of commands. |
void |
setWorkingDirectory(java.io.File workingDirectory)
Set the working directory of the subprocess. |
void |
start()
Start running the commands. |
void |
stderr(java.lang.String text)
Append the text message to stderr. |
void |
stdout(java.lang.String text)
Append the text message to the output. |
static java.lang.String[] |
updateEnvironment(java.lang.String key,
java.lang.String value)
Update the environment and return the results. |
void |
updateStatusBar(java.lang.String text)
Set the text of the status bar. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private java.util.List _commands
private final boolean _debug
private java.lang.String[] _envp
name=value
. If this variable is null, then
the environment of the calling process is used.
private java.lang.Process _process
private int _subprocessReturnCode
private java.io.File _workingDirectory
Constructor Detail |
---|
public StreamExec()
Method Detail |
---|
public void appendToPath(java.lang.String directoryName)
appendToPath
in interface ExecuteCommands
directoryName
- The name of the directory to append to the path.public void cancel()
cancel
in interface ExecuteCommands
public void clear()
clear
in interface ExecuteCommands
public java.lang.String getenv(java.lang.String key)
getenv
in interface ExecuteCommands
key
- The key for which to search.
public int getLastSubprocessReturnCode()
getLastSubprocessReturnCode
in interface ExecuteCommands
public void setCommands(java.util.List commands)
setCommands
in interface ExecuteCommands
commands
- A list of Strings, where each element is a command.public void setWorkingDirectory(java.io.File workingDirectory)
setWorkingDirectory
in interface ExecuteCommands
workingDirectory
- The working directory of the
subprocess. If this argument is null, then the subprocess is
executed in the working directory of the current process.public void start()
start
in interface ExecuteCommands
public void stderr(java.lang.String text)
stderr
in interface ExecuteCommands
text
- The text to append to standard error.public void stdout(java.lang.String text)
stdout
in interface ExecuteCommands
text
- The text to append to standard out.public static java.lang.String[] updateEnvironment(java.lang.String key, java.lang.String value)
key
- The environment variable to be updated.value
- The value to append
name=value
with the environment variable
named by the key parameter updated to include the value
of the value parameter.public void updateStatusBar(java.lang.String text)
updateStatusBar
in interface ExecuteCommands
text
- The text with which the status bar is updated.protected void _setProgressBarMaximum(int size)
size
- The maximum size of the progress bar.private java.lang.String _executeCommands()
private void _updateProgressBar(int i)
i
- The current location of the progress bar.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |