Package org.scijava.util
Class ProcessUtils
- java.lang.Object
-
- org.scijava.util.ProcessUtils
-
public final class ProcessUtils extends Object
Useful methods for working with processes.- Author:
- Johannes Schindelin
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringexec(File workingDirectory, InputStream in, PrintStream err, PrintStream out, String... args)Executes a program.static Stringexec(File workingDirectory, PrintStream err, PrintStream out, String... args)Executes a program.
-
-
-
Method Detail
-
exec
public static String exec(File workingDirectory, PrintStream err, PrintStream out, String... args)
Executes a program. This is a convenience method mainly to be able to catch the output of programs as shell scripts can do by wrapping calls in $(...).- Parameters:
workingDirectory- the directory in which to execute the programerr- thePrintStreamto print the program's error stream to; if null is passed, the error goes straight to Nirvana (not the band, though).out- thePrintStreamto print the program's output to; if null is passed, the output will be accumulated into aStringand returned upon exit.args- the command-line to execute, split into components- Returns:
- the output of the program if
outis null, otherwise an emptyString - Throws:
RuntimeException- if interrupted or the program failed to execute successfully.
-
exec
public static String exec(File workingDirectory, InputStream in, PrintStream err, PrintStream out, String... args)
Executes a program. This is a convenience method mainly to be able to catch the output of programs as shell scripts can do by wrapping calls in $(...).- Parameters:
workingDirectory- the directory in which to execute the programin- theInputStreamwhich gets fed to the program as standard input;err- thePrintStreamto print the program's error stream to; if null is passed, the error goes straight to Nirvana (not the band, though).out- thePrintStreamto print the program's output to; if null is passed, the output will be accumulated into aStringand returned upon exit.args- the command-line to execute, split into components- Returns:
- the output of the program if
outis null, otherwise an emptyString - Throws:
RuntimeException- if interrupted or the program failed to execute successfully.
-
-