|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ibm.jzos.Exec
public class Exec
Class for running an external process that buffers output, provides timeout control and stdout/stderr character encoding.
The process' error output is buffered in a separate thread to keep the process from blocking and timing out.
Process flow:
Runtime.exec(java.lang.String)
style constructors.
run()
readLine()
until EOF is encountered
getReturnCode()
. This step is
necessary to join the stderr thread.
getErrorLines()
For an example see: main(String[])
Field Summary | |
---|---|
static java.lang.String |
CHILD_PROCESS_INPUT_ENCODING_PROPERTY
|
Constructor Summary | |
---|---|
Exec(java.lang.String command)
Construct an instance. |
|
Exec(java.lang.String[] cmdargs)
Construct an instance with a tokenized command. |
|
Exec(java.lang.String[] cmdargs,
java.lang.String[] envp)
Construct an instance with a tokenized command and environment. |
|
Exec(java.lang.String[] cmdargs,
java.lang.String[] envp,
java.io.File dir)
Construct an instance with a tokenzied command, environment and working dir |
|
Exec(java.lang.String command,
java.lang.String[] envp)
Construct an instance with a given commmand and environment. |
|
Exec(java.lang.String command,
java.lang.String[] envp,
java.io.File dir)
Construct an instance with a given command, environment, and working directory. |
Method Summary | |
---|---|
void |
consumeOutput()
Convenience method to drain the external process stdout lines. |
void |
consumeOutput(java.lang.StringBuffer buf)
Convenience method to read the external process stdout lines into the supplied StringBuffer. |
static java.lang.String |
getChildProcessInputEncoding()
Return the default encoding to use for sending data to child process's stdin stream. |
java.util.List |
getErrorLines()
Answer the error lines buffered from the external process. |
int |
getMaxErrorLines()
Answer the current maxErrorLines setting. |
java.io.BufferedReader |
getOutputReader()
Return a BufferedReader on the external process stdout stream. |
int |
getReturnCode()
Once all output is read (stderr and stdout), this method is called to wait for the process to complete and retrieve the exit value. |
java.io.OutputStream |
getStdinStream()
Answer an OutputStream which is connected to the stdin input of the external process. |
java.io.BufferedWriter |
getStdinWriter()
Return a BufferedWriter to the child's stdin. |
java.io.InputStream |
getStdoutStream()
Return an InputStream on the external process stdout stream. |
boolean |
isDestroyed()
Answer true if the external process has been destroyed. |
boolean |
isTimedOut()
Answer true if the external process was destroyed due to timeout. |
static void |
main(java.lang.String[] args)
An example main method for launching a command from main args |
java.lang.String |
readLine()
Reads a line from the external process stdout stream. |
void |
run()
Create (and start) the Runtime.exec process. |
void |
setMaxErrorLines(int maxErrorLines)
Set the limit for how many of the external process stderr lines will be kept. |
void |
setTimeout(int timeout)
Sets the length of time, in milliseconds, to wait for the external process if no response (stdout or stderr) is received. |
void |
updateHealthTimer()
Reset the health timer for the external process. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String CHILD_PROCESS_INPUT_ENCODING_PROPERTY
Constructor Detail |
---|
public Exec(java.lang.String command)
Runtime.exec(java.lang.String)
public Exec(java.lang.String command, java.lang.String[] envp)
Runtime.exec(java.lang.String, java.lang.String[])
public Exec(java.lang.String command, java.lang.String[] envp, java.io.File dir)
Runtime.exec(java.lang.String, java.lang.String[], java.io.File)
public Exec(java.lang.String[] cmdargs)
Runtime.exec(java.lang.String[])
public Exec(java.lang.String[] cmdargs, java.lang.String[] envp)
Runtime.exec(java.lang.String[], java.lang.String[])
public Exec(java.lang.String[] cmdargs, java.lang.String[] envp, java.io.File dir)
Runtime.exec(java.lang.String[], java.lang.String[], java.io.File)
Method Detail |
---|
public static void main(java.lang.String[] args) throws java.io.IOException
args
- the command to run
java.io.IOException
public static java.lang.String getChildProcessInputEncoding()
SDKs prior to Java 5.0 SR3 should use ZUtil.getCodePageCurrentLocale() whereas later SDKs should use the default JVM file.encoding since automatic transcoding of the child stdin data is done by Runtime.exec().
This method returns the encoding to use:
public java.util.List getErrorLines()
public void setMaxErrorLines(int maxErrorLines)
maxErrorLines
- maximum lines to keep. Zero sets no limit.public int getMaxErrorLines()
public int getReturnCode()
public java.io.OutputStream getStdinStream()
public java.io.BufferedWriter getStdinWriter()
This method should not be used while also using getStdinStream() directly.
getChildProcessInputEncoding()
public void setTimeout(int timeout)
timeout
- millisecond timeout. Zero disables timeout checking.public void consumeOutput(java.lang.StringBuffer buf) throws java.io.IOException
buf
- The buffer to hold the stdout lines.
java.io.IOException
public void consumeOutput() throws java.io.IOException
java.io.IOException
public java.lang.String readLine() throws java.io.IOException
After each line is read, the timeout health time is updated
java.io.IOException
public java.io.BufferedReader getOutputReader()
This method should not be used while also using getStdoutStream() directly.
public java.io.InputStream getStdoutStream()
This method should not be used in combination with getOutputReader()
.
public boolean isDestroyed()
public boolean isTimedOut()
public void run() throws java.io.IOException
java.io.IOException
public void updateHealthTimer()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |