|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.perdues.ProcessUtils
public class ProcessUtils
Convenient class to run a native command-line program from Java and receive its output and exit status. The simplest method returns the program's standard output to you as a String and throws an exception in case of nonzero exit status or error output. This class was inspired by the convenience of the Tcl "exec" function.
Nested Class Summary | |
---|---|
static class |
ProcessUtils.Exception
This Exception class reports error exit status, all standard output and error output from an external program. |
Method Summary | |
---|---|
static String |
exec(String[] cmd)
Runs a command-line program and returns all of its standard output as a String. |
static int |
exec(String[] cmd,
InputStream input,
OutputStream output,
OutputStream errors)
Runs a command-line program, writes all of its standard output and error output to two OutputStreams, returns its final exit status, and makes your InputStream available to the program. |
static int |
exec(String[] cmd,
OutputStream output,
OutputStream errors)
Runs a command-line program, writes all of its standard output and error output to two OutputStreams, and returns its final exit status. |
static int |
exec(String[] cmd,
Reader input,
Writer output,
Writer errors)
Runs a command-line program, writes all of its standard output and error output to two Writers, returns its final exit status, and makes your Reader available to the program. |
static int |
exec(String[] cmd,
Writer output,
Writer errors)
Runs a command-line program, passes its standard output and error output to two Writers, and returns its final exit status. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static String exec(String[] cmd) throws IOException, InterruptedException
ProcessUtils.Exception
- in case of nonzero exit status or error
output.
IOException
InterruptedException
public static int exec(String[] cmd, Writer output, Writer errors) throws IOException, InterruptedException
IOException
InterruptedException
public static int exec(String[] cmd, Reader input, Writer output, Writer errors) throws IOException, InterruptedException
This will complete even if the program only reads part of its input, and before returning it interrupts the thread that feeds input to the program. Reads on some Readers do not unblock on interrupts, so the input thread may live until the last read completes.
IOException
InterruptedException
public static int exec(String[] cmd, OutputStream output, OutputStream errors) throws IOException, InterruptedException
IOException
InterruptedException
public static int exec(String[] cmd, InputStream input, OutputStream output, OutputStream errors) throws IOException, InterruptedException
This will complete even if the program only reads part of its input, and before returning it interrupts the thread that feeds input to the program. Reads on some InputStreams do not unblock on interrupts, so the input thread may live until the last read completes.
IOException
InterruptedException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |