Java Reference
In-Depth Information
plugTogether(System.in, proc.getOutputStream());
plugTogether(System.out, proc.getInputStream());
plugTogether(System.err, proc.getErrorStream());
return proc;
}
// ... definition of plugTogether ...
This code assumes that a method
plugTogether
exists to connect two
streams by reading the bytes from one stream and writing them onto
the other.
The second way a
Process
object represents the child process is by
providing methods to control the process and discover its termination
status:
public abstract int
waitFor()
tHRows InterruptedException
Waits indefinitely for the process to complete, returning the
value it passed to either
System.exit
or its equivalent (zero
means success, nonzero means failure). If the process has
already completed, the value is simply returned.
public abstract int
exitValue()
Returns the exit value for the process. If the process has not
completed,
exitValue
throws
IllegalThreadStateException
.
public abstract void
destroy()
Kills the process. Does nothing if the process has already
completed. Garbage collection of a
Process
object does not
mean that the process is destroyed; it will merely be unavail-
able for manipulation.
For example, the following method returns a
String
array that contains
the output of the
ls
command with the specified command-line argu-