|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectch.javasoft.job.ExecJob
public class ExecJob
An ExecJob represents a command line executable, such as those
being passed to Runtime.exec(String) and related methods.
A sample usage of this class, piping 2 jobs and displaying the results on the standard output/error could look like this:
public void pipe2Jobs() throws Exception {
ExecJob job1 = new ExecJob("cat /tmp/efms.txt");
ExecJob job2 = new ExecJob("grep 191");
ExecJobMonitor hdl1 = job1.exec();
ExecJobMonitor hdl2 = job2.exec();
hdl1.pipeTo(hdl2, true);
hdl2.pipeTo(System.out, System.err, false);
hdl2.waitForResult();
System.out.println("DONE.");
}
| Constructor Summary | |
|---|---|
ExecJob(String command)
Constructs an ExecJob with the specified string command |
|
ExecJob(String[] cmdarray)
Constructs an ExecJob with the specified string command |
|
ExecJob(String[] cmdarray,
File dir)
Constructs an ExecJob with the specified string command and working directory. |
|
ExecJob(String[] cmdarray,
String[] envp)
Constructs an ExecJob with the specified string command and environment. |
|
ExecJob(String[] cmdarray,
String[] envp,
File dir)
Constructs an ExecJob with the specified string command, environment and working directory. |
|
ExecJob(String command,
File dir)
Constructs an ExecJob with the specified string command and working directory. |
|
ExecJob(String command,
String[] envp)
Constructs an ExecJob with the specified string command and environment. |
|
ExecJob(String command,
String[] envp,
File dir)
Constructs an ExecJob with the specified string command, environment and working directory. |
|
| Method Summary | ||
|---|---|---|
ExecJobMonitor |
exec()
Executes and returns immediately, without waiting for completion. |
|
ExecJobMonitor |
exec(JobTerminationHandler<Void> terminationHandler)
Executes and returns immediately, without waiting for completion. |
|
JobResult<Void> |
execAndWait()
Executes and waits for completion. |
|
Void |
execAndWaitThrowException()
Executes and waits for completion. |
|
|
execWaitForResultThrowException(Class<E> exClass)
Like execAndWait(), but if the result was exceptional, an
Exception is thrown. |
|
String |
execWaitForStdOutString()
Like execAndWait(), but returning a string containing the
stuff which was written to the standard output of the process. |
|
Object |
id()
|
|
ExecJobMonitor |
run()
Executes the job, blocks until the result is present or an exception is thrown. |
|
String |
toString()
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public ExecJob(String command)
This is a convenience method. An invocation of the form
ExecJob(command)
behaves in exactly the same way as the invocation
exec(command, null, null).
command - a specified system command.
NullPointerException - if command is nullRuntime.exec(String)
public ExecJob(String command,
String[] envp)
This is a convenience method. An invocation of the form
ExecJob(command, envp)
behaves in exactly the same way as the invocation
exec(command, envp, null).
command - a specified system command.envp - array of strings, each element of which
has environment variable settings in the format
name=value, or
null if the subprocess should inherit
the environment of the current process.
NullPointerException - if command is nullRuntime.exec(String, String[]),
Env
public ExecJob(String command,
File dir)
This is a convenience method. An invocation of the form
ExecJob(command, dir)
behaves in exactly the same way as the invocation
exec(command, null, dir).
command - a specified system command.dir - the working directory of the subprocess, or
null if the subprocess should inherit
the working directory of the current process.
NullPointerException - if command is nullRuntime.exec(String, String[], File),
Env
public ExecJob(String command,
String[] envp,
File dir)
command - a specified system command.envp - array of strings, each element of which
has environment variable settings in the format
name=value, or
null if the subprocess should inherit
the environment of the current process.dir - the working directory of the subprocess, or
null if the subprocess should inherit
the working directory of the current process.
NullPointerException - if command is nullRuntime.exec(String, String[], File),
Envpublic ExecJob(String[] cmdarray)
This is a convenience method. An invocation of the form
ExecJob(command)
behaves in exactly the same way as the invocation
exec(command, null, null).
cmdarray - array containing the command to call and
its arguments.
NullPointerException - if command is nullRuntime.exec(String)
public ExecJob(String[] cmdarray,
String[] envp)
This is a convenience method. An invocation of the form
ExecJob(command, envp)
behaves in exactly the same way as the invocation
exec(command, envp, null).
cmdarray - array containing the command to call and
its arguments.envp - array of strings, each element of which
has environment variable settings in the format
name=value, or
null if the subprocess should inherit
the environment of the current process.
NullPointerException - if command is nullRuntime.exec(String, String[]),
Env
public ExecJob(String[] cmdarray,
File dir)
This is a convenience method. An invocation of the form
ExecJob(command, dir)
behaves in exactly the same way as the invocation
exec(command, null, dir).
cmdarray - array containing the command to call and
its arguments.dir - the working directory of the subprocess, or
null if the subprocess should inherit
the working directory of the current process.
NullPointerException - if command is nullRuntime.exec(String, String[], File),
Env
public ExecJob(String[] cmdarray,
String[] envp,
File dir)
cmdarray - array containing the command to call and
its arguments.envp - array of strings, each element of which
has environment variable settings in the format
name=value, or
null if the subprocess should inherit
the environment of the current process.dir - the working directory of the subprocess, or
null if the subprocess should inherit
the working directory of the current process.
NullPointerException - if command is nullRuntime.exec(String, String[], File),
Env| Method Detail |
|---|
public Object id()
this)
public ExecJobMonitor run()
throws IOException
JobJobProcessor. Most job
implementations also implement Executable with the more
preferable Executable.exec() and Executable.execAndWait()
methods.
run in interface Job<ExecJobMonitor>null of type Void for
void methods
IOExceptionpublic ExecJobMonitor exec()
Executable
exec in interface Executable<Void>public ExecJobMonitor exec(JobTerminationHandler<Void> terminationHandler)
Executable
exec in interface Executable<Void>terminationHandler - the handler for normal and exceptional termination of this job
public JobResult<Void> execAndWait()
throws InterruptedException
Executable
execAndWait in interface Executable<Void>InterruptedException
public Void execAndWaitThrowException()
throws InterruptedException,
Throwable
Executable
execAndWaitThrowException in interface Executable<Void>InterruptedException
Throwable
public <E extends Throwable> void execWaitForResultThrowException(Class<E> exClass)
throws E extends Throwable
execAndWait(), but if the result was exceptional, an
Exception is thrown. The exception type to be thrown is defined with the
exClass parameter, every exception not being of that type
will be transformed into a RuntimeException if necessary.
exClass - The desired exception type, e.g. use
RuntimeException.class that only runtime
exceptions are thrown, or Throwable.class
to rethrow every occuring exception unchanged.
E - The exception of the specified type
RuntimeException - If an exception was thrown not being of type E
and not being an Error. If it was already a
runtime exception, it is rethrown, if not, it
is nested in a runtime exception which is then
thrown.
Error - If an error was thrown not being of type E
E extends Throwable
public String execWaitForStdOutString()
throws ExecException,
ExitValueException,
StdErrNonEmptyException,
InterruptedException
execAndWait(), but returning a string containing the
stuff which was written to the standard output of the process. If the
process also wrote to the standard error, a
StdErrNonEmptyException is thrown. If the process exits with an
exit code unequal to 0, an ExitValueException is thrown.
ExitValueException - if the process terminated with an exit
value unequal to 0
StdErrNonEmptyException - if the process wrote to the standard
error
InterruptedException - if waiting for termination of the
process was interrupted, e.g.
by calling ExecJobMonitor.interrupt()
ExecException - if any other exception occurred during
the process executionpublic String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||