public class ProcessTools
extends java.lang.Object
java.lang.Process API,
but hides away the details of managing threads and process I/O.
StringWriter out = new StringWriter();
ProcessTools.exec(
new String[] {"/usr/bin/wc", "-w"},
"The quick brown fox jumps over the lazy dog",
out,
null
);
int numWords = Integer.parseInt(out.toString().trim());
| Modifier and Type | Method and Description |
|---|---|
static int |
exec(java.lang.String[] args,
java.io.Reader input,
java.io.Writer stdout,
java.io.Writer stderr)
Deprecated.
Execute the specified command and wait for it to return.
|
static int |
exec(java.lang.String[] args,
java.lang.String[] envp,
java.io.File dir,
java.io.Reader input,
java.io.Writer stdout,
java.io.Writer stderr,
long timeout)
Deprecated.
Execute the specified command and wait for it to return, or kill
it if the specified timeout expires first.
|
static int |
exec(java.lang.String command,
java.io.Reader input,
java.io.Writer stdout,
java.io.Writer stderr)
Deprecated.
Execute the specified command and wait for it to return.
|
static int |
exec(java.lang.String command,
java.lang.String[] envp,
java.io.File dir,
java.io.Reader input,
java.io.Writer stdout,
java.io.Writer stderr,
long timeout)
Deprecated.
Execute the specified command and wait for it to return.
|
public static int exec(java.lang.String[] args,
java.io.Reader input,
java.io.Writer stdout,
java.io.Writer stderr)
throws java.io.IOException
args - the command line to execute.input - data to present to the process' standard input, or null if the process does not require input.stdout - a Writer which will be filled with data from the process' output stream, or null to ignore output.stderr - a Writer which will be filled with data from the process' error stream, or null to ignore output.java.io.IOExceptionpublic static int exec(java.lang.String[] args,
java.lang.String[] envp,
java.io.File dir,
java.io.Reader input,
java.io.Writer stdout,
java.io.Writer stderr,
long timeout)
throws java.io.IOException,
ProcessTimeoutException
args - the command line to execute.envp - environment variables for the child process, or null to inherit the current set.dir - working directory for the child process, or null to inherit the current directory.input - data to present to the process' standard input, or null if the process does not require input.stdout - a Writer which will be filled with data from the process' output stream, or null to ignore output.stderr - a Writer which will be filled with data from the process' error stream, or null to ignore output.timeout - maximum run-time (in milliseconds) for the child process. A value of 0 indicates no limit.java.io.IOException - if an error occurs while starting or communicating with the processProcessTimeoutException - if the child process was killed because its timeout had expired.public static int exec(java.lang.String command,
java.io.Reader input,
java.io.Writer stdout,
java.io.Writer stderr)
throws java.io.IOException
command - the command line to execute.input - data to present to the process' standard input, or
null if the process does not require input.stdout - a Writer which will be filled with data
from the process' output stream, or null to ignore output.stderr - a Writer which will be filled with data
from the process' error stream, or null to ignore output.java.io.IOException - if an error occurs while starting or communicating
with the processpublic static int exec(java.lang.String command,
java.lang.String[] envp,
java.io.File dir,
java.io.Reader input,
java.io.Writer stdout,
java.io.Writer stderr,
long timeout)
throws java.io.IOException,
ProcessTimeoutException
command - the command line to execute.input - data to present to the process' standard input, or
null if the process does not require input.stdout - a Writer which will be filled with data
from the process' output stream, or null to ignore output.stderr - a Writer which will be filled with data
from the process' error stream, or null to ignore output.timeout - maximum run-time (in milliseconds) for the child process. A value of 0 indicates no limit.java.io.IOException - if an error occurs while starting or communicating
with the processProcessTimeoutException - if the child process was killed because its timeout had expired.