Package org.biojava.utils
Class ProcessTools
- java.lang.Object
-
- org.biojava.utils.ProcessTools
-
public class ProcessTools extends Object
Deprecated.preferable to use org.biojava.utils.ExecRunner or the org.biojava.utils.process package.Convenience methods for running external processes. This class offers wrappers around thejava.lang.Process
API, but hides away the details of managing threads and process I/O.Example
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());
- Since:
- 1.4
- Author:
- Thomas Down, Francois Pepin
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static int
exec(String[] args, Reader input, Writer stdout, Writer stderr)
Deprecated.Execute the specified command and wait for it to return.static int
exec(String[] args, String[] envp, File dir, Reader input, Writer stdout, 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(String command, Reader input, Writer stdout, Writer stderr)
Deprecated.Execute the specified command and wait for it to return.static int
exec(String command, String[] envp, File dir, Reader input, Writer stdout, Writer stderr, long timeout)
Deprecated.Execute the specified command and wait for it to return.
-
-
-
Method Detail
-
exec
public static int exec(String[] args, Reader input, Writer stdout, Writer stderr) throws IOException
Deprecated.Execute the specified command and wait for it to return.- Parameters:
args
- the command line to execute.input
- data to present to the process' standard input, ornull
if the process does not require input.stdout
- aWriter
which will be filled with data from the process' output stream, ornull
to ignore output.stderr
- aWriter
which will be filled with data from the process' error stream, ornull
to ignore output.- Returns:
- the process' return code.
- Throws:
IOException
-
exec
public static int exec(String[] args, String[] envp, File dir, Reader input, Writer stdout, Writer stderr, long timeout) throws IOException, ProcessTimeoutException
Deprecated.Execute the specified command and wait for it to return, or kill it if the specified timeout expires first.- Parameters:
args
- the command line to execute.envp
- environment variables for the child process, ornull
to inherit the current set.dir
- working directory for the child process, ornull
to inherit the current directory.input
- data to present to the process' standard input, ornull
if the process does not require input.stdout
- aWriter
which will be filled with data from the process' output stream, ornull
to ignore output.stderr
- aWriter
which will be filled with data from the process' error stream, ornull
to ignore output.timeout
- maximum run-time (in milliseconds) for the child process. A value of 0 indicates no limit.- Returns:
- the process' return code.
- Throws:
IOException
- if an error occurs while starting or communicating with the processProcessTimeoutException
- if the child process was killed because its timeout had expired.
-
exec
public static int exec(String command, Reader input, Writer stdout, Writer stderr) throws IOException
Deprecated.Execute the specified command and wait for it to return. This is the simplified version that tries to be nice and make your life easier. If you know exactly what you want, you might want to use exec(String[],...) instead.- Parameters:
command
- the command line to execute.input
- data to present to the process' standard input, ornull
if the process does not require input.stdout
- aWriter
which will be filled with data from the process' output stream, ornull
to ignore output.stderr
- aWriter
which will be filled with data from the process' error stream, ornull
to ignore output.- Returns:
- the process' return code.
- Throws:
IOException
- if an error occurs while starting or communicating with the process
-
exec
public static int exec(String command, String[] envp, File dir, Reader input, Writer stdout, Writer stderr, long timeout) throws IOException, ProcessTimeoutException
Deprecated.Execute the specified command and wait for it to return. This is the simplified version that tries to be nice and make your life easier. If you know exactly what you want, you might want to use exec(String[],...) instead.- Parameters:
command
- the command line to execute.input
- data to present to the process' standard input, ornull
if the process does not require input.stdout
- aWriter
which will be filled with data from the process' output stream, ornull
to ignore output.stderr
- aWriter
which will be filled with data from the process' error stream, ornull
to ignore output.timeout
- maximum run-time (in milliseconds) for the child process. A value of 0 indicates no limit.- Returns:
- the process' return code.
- Throws:
IOException
- if an error occurs while starting or communicating with the processProcessTimeoutException
- if the child process was killed because its timeout had expired.
-
-