|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Thread
com.sun.electric.tool.user.Exec
public class Exec
Runtime.exec() has many pitfalls to it's proper use. This class wraps external executes to make it easier to use.
Usage:
Exec exec = new Exec("ls", null, User.getWorkingDirectory(), System.out, System.out);
exec.start(); // run in a new Thread
You can also use exec.run() to run in the current thread.
| Nested Class Summary | |
|---|---|
static class |
Exec.ExecProcessReader
This class is used to read data from an external process. |
static class |
Exec.FinishedEvent
The event passed to listeners when the process finishes |
static interface |
Exec.FinishedListener
Objects that want to be notified of the process finishing should implement this interface, and add themselves as a listener to the process. |
static class |
Exec.OutputStreamChecker
Check for a string passed to the OutputStream. |
static interface |
Exec.OutputStreamCheckerListener
Interface for objects to be notified immediately when OutputStreamChecker matches when it is looking for. |
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
| Field Summary |
|---|
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
Exec(java.lang.String[] exec,
java.lang.String[] envVars,
java.io.File dir,
java.io.OutputStream outStreamRedir,
java.io.OutputStream errStreamRedir)
Execute an external process. |
|
Exec(java.lang.String command,
java.lang.String[] envVars,
java.io.File dir,
java.io.OutputStream outStreamRedir,
java.io.OutputStream errStreamRedir)
Execute an external process. |
|
| Method Summary | |
|---|---|
void |
addFinishedListener(Exec.FinishedListener a)
Add a Exec.FinishedListener |
void |
destroyProcess()
End this process, if it is running. |
int |
getExitVal()
|
void |
removeFinishedListener(Exec.FinishedListener a)
Remove a Exec.FinishedListener |
void |
run()
|
void |
writeln(java.lang.String line)
Send a line of text to the process. |
| Methods inherited from class java.lang.Thread |
|---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Exec(java.lang.String command,
java.lang.String[] envVars,
java.io.File dir,
java.io.OutputStream outStreamRedir,
java.io.OutputStream errStreamRedir)
/bin/sh -c /bin/ls > file.txt will NOT work.
Instead, use String[] exec = {"/bin/sh", "-c", "/bin/ls > file.txt"}; and use the other constructor.
command - the command to run.envVars - environment variables of the form name=value. If null, inherits vars from current process.dir - the working directory. If null, uses the working dir from the current processoutStreamRedir - stdout of the process will be redirected to this stream if not nullerrStreamRedir - stderr of the process will be redirected to this stream if not null
public Exec(java.lang.String[] exec,
java.lang.String[] envVars,
java.io.File dir,
java.io.OutputStream outStreamRedir,
java.io.OutputStream errStreamRedir)
exec - the executable and arguments of the processenvVars - environment variables of the form name=value. If null, inherits vars from current process.dir - the working directory. If null, uses the working dir from the current processoutStreamRedir - stdout of the process will be redirected to this stream if not nullerrStreamRedir - stderr of the process will be redirected to this stream if not null| Method Detail |
|---|
public void run()
run in interface java.lang.Runnablerun in class java.lang.Threadpublic void writeln(java.lang.String line)
line - a line of text to send to the processpublic void addFinishedListener(Exec.FinishedListener a)
a - the listenerpublic void removeFinishedListener(Exec.FinishedListener a)
a - the listenerpublic void destroyProcess()
public int getExitVal()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||