|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectptolemy.util.StreamExec
ptolemy.util.StringBufferExec
public class StringBufferExec
Execute commands in a subprocess and accumulate the output in a StringBuffer.
As an alternative to this class, see
JTextAreaExec, which uses Swing; and
StreamExec, which writes to stderr and stdout.
Sample usage:
List execCommands = new LinkedList();
execCommands.add("date");
execCommands.add("sleep 3");
execCommands.add("date");
execCommands.add("notACommand");
final StringBufferExec exec = new StringBufferExec();
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
| Red (cxh) |
| Red (cxh) |
| Field Summary | |
|---|---|
private boolean |
_appendToStderrAndStdout
If true, append to stderr and stdout as the commands are executed. |
private static java.lang.String |
_eol
End of line character. |
java.lang.StringBuffer |
buffer
The StringBuffer to which the output is appended. |
| Constructor Summary | |
|---|---|
StringBufferExec()
Create a StringBufferExec. |
|
StringBufferExec(boolean appendToStderrAndStdout)
Create a StringBufferExec and optionally append to stderr and stdout as the commands are executed. |
|
| Method Summary | |
|---|---|
private void |
_appendToBuffer(java.lang.String text)
Append to the internal StringBuffer. |
void |
stderr(java.lang.String text)
Append the text message to the StringBuffer. |
void |
stdout(java.lang.String text)
Append the text message to the StringBuffer. |
| Methods inherited from class ptolemy.util.StreamExec |
|---|
_setProgressBarMaximum, appendToPath, cancel, clear, getenv, getLastSubprocessReturnCode, setCommands, setWorkingDirectory, start, updateEnvironment, updateStatusBar |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public java.lang.StringBuffer buffer
private boolean _appendToStderrAndStdout
private static java.lang.String _eol
| Constructor Detail |
|---|
public StringBufferExec()
public StringBufferExec(boolean appendToStderrAndStdout)
appendToStderrAndStdout - If true, then as the commands
are executed, the output is append to stderr and stdout.| Method Detail |
|---|
public void stderr(java.lang.String text)
stderr in interface ExecuteCommandsstderr in class StreamExectext - The text to append.public void stdout(java.lang.String text)
stdout in interface ExecuteCommandsstdout in class StreamExectext - The text to append.private void _appendToBuffer(java.lang.String text)
text - The text to append. If the text does not
end with an end of line character(s), then _eol is appended.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||