|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectverinec.util.AbstractProgramExec
verinec.util.ProgramExec
public class ProgramExec
Wrapper methods for execution of native programs via the Runtime.exec().
These methods provide for simpler program execution, allowing to redirect program output or input to files (the < / > parameters in a shell), or retrieving the output as a stream. They allow to set a timeout after which program execution is interrupted.
You can execute a program and wait for its result, or execute it asynchronous, that is in a separate thread without waiting for it to finish.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class verinec.util.AbstractProgramExec |
|---|
AbstractProgramExec.StreamGobbler, AbstractProgramExec.TimeoutWatcher |
| Field Summary |
|---|
| Fields inherited from class verinec.util.AbstractProgramExec |
|---|
cwd, timedOut |
| Constructor Summary | |
|---|---|
ProgramExec(String commandline,
File cwd,
InputStream stdin,
OutputStream stdout,
OutputStream stderr)
Prepare a program execution. |
|
| Method Summary | |
|---|---|
static int |
execSync(String commandline,
File cwd,
InputStream stdin,
OutputStream stdout,
OutputStream stderr,
int timeout)
Execute a program and wait for it to terminate. |
protected Process |
startProcess(String commandline,
File cwd)
Instantiate a process using Runtime. |
| Methods inherited from class verinec.util.AbstractProgramExec |
|---|
abortExecution, execAsync, execSync, exitValue, hasFinished |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ProgramExec(String commandline,
File cwd,
InputStream stdin,
OutputStream stdout,
OutputStream stderr)
The input for the program can be given as an InputStream that will be piped to the program as stdin. If you have a file as input, you can use java.io.FileInputStream. stdin can be null, in which case no input is given to the program.
The output can be pushed into OutputStreams for later treatment. If both streams are null, output is discarded. If the stdout stream is null only, errors are written into stderr, if stderr is null, both out and err written into stdout. Again, you can use FileOutputStream to write into files. The streams will be closed when the program execution is finished.
It is recommended to wrap the output streams with a BufferedOutputStream to avoid delays.
commandline - Name of the executable with all parameters. (Do not forget full path if executable is not in the path for programs).cwd - The current working directory directory for the new process (defaults to the system property user.dir if null).stdin - A Stream that will be fed to the process as input (ignored if null).stdout - A Stream to write the program output into (discarded if null).stderr - A Stream to write the program error output into (redirected to stdout if null).| Method Detail |
|---|
public static int execSync(String commandline,
File cwd,
InputStream stdin,
OutputStream stdout,
OutputStream stderr,
int timeout)
throws InterruptedException,
VerinecException
The input for the program can be given as an InputStream that will be piped to the program as stdin. If you have a file as input, you can use java.io.FileInputStream. stdin can be null, in which case no input is given to the program.
The output can be pushed into OutputStreams for later treatment. If both streams are null, output is discarded. If the stdout stream is null only, errors are written into stderr, if stderr is null, both out and err written into stdout. Again, you can use FileOutputStream to write into files. The streams will be closed when the program execution is finished.
It is recommended to wrap the output streams with a BufferedOutputStream to avoid delays.
commandline - Name of the executable with all parameters. (Do not forget full path if executable is not in the path for programs).stdin - A Stream that will be fed to the process as input (ignored if null).stdout - A Stream to write the program output into (discarded if null).stderr - A Stream to write the program error output into (redirected to stdout if null).cwd - The current working directory directory for the new process (defaults to the system property user.dir if null).timeout - The time in seconds after which the execution should be interrupted (0 for no timeout).
InterruptedException - If the timeout occurs or the process is otherwise interrupted.
VerinecException - If other errors occur.
protected Process startProcess(String commandline,
File cwd)
throws VerinecException
startProcess in class AbstractProgramExeccommandline - The command line to execute.cwd - The current working directory for the command.
VerinecException - If the command is not found.
|
Copyright © 2005 Verinec, DIUF | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||