Package ptolemy.util
Class StringBufferExec
- java.lang.Object
-
- ptolemy.util.StreamExec
-
- ptolemy.util.StringBufferExec
-
- All Implemented Interfaces:
ExecuteCommands
public class StringBufferExec extends StreamExec
Execute commands in a subprocess and accumulate the output in a StringBuffer.As an alternative to this class, see
JTextAreaExec
, which uses Swing; andStreamExec
, 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(); String result = exec.buffer.toString();
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
- Since:
- Ptolemy II 6.1
- Version:
- $Id$
- Author:
- Christopher Brooks
- See Also:
JTextAreaExec
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Red (cxh)
-
-
Field Summary
Fields Modifier and Type Field Description java.lang.StringBuffer
buffer
The StringBuffer to which the output is appended.
-
Constructor Summary
Constructors Constructor Description StringBufferExec()
Create a StringBufferExec.StringBufferExec(boolean appendToStderrAndStdout)
Create a StringBufferExec and optionally append to stderr and stdout as the commands are executed.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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, getPatternLog, setCommands, setPattern, setWaitForLastSubprocess, setWorkingDirectory, start, updateEnvironment, updateStatusBar
-
-
-
-
Constructor Detail
-
StringBufferExec
public StringBufferExec()
Create a StringBufferExec. As the commands are executed, output is appended to the StringBuffer - no output will appear on stderr and stdout.
-
StringBufferExec
public StringBufferExec(boolean appendToStderrAndStdout)
Create a StringBufferExec and optionally append to stderr and stdout as the commands are executed.- Parameters:
appendToStderrAndStdout
- If true, then as the commands are executed, the output is append to stderr and stdout.
-
-
Method Detail
-
stderr
public void stderr(java.lang.String text)
Append the text message to the StringBuffer. The output automatically gets a trailing end of line character(s) appended. Optionally, the text also appears on stderr- Specified by:
stderr
in interfaceExecuteCommands
- Overrides:
stderr
in classStreamExec
- Parameters:
text
- The text to append.
-
stdout
public void stdout(java.lang.String text)
Append the text message to the StringBuffer. The output automatically gets end of line character(s) appended. Optionally, the text also appears on stdout.- Specified by:
stdout
in interfaceExecuteCommands
- Overrides:
stdout
in classStreamExec
- Parameters:
text
- The text to append.
-
-