The Process
instance can help you manipulate the execution of your runtime through its InputStream and Outpustream.
The process instance has a waitFor()
method that allows the current Thread
to wait for the termination of the subprocess.
To control the completion of your process, you can also get the exitValue
of your runtime, but this depends on what the process returns.
Here is a simple example of how to use the waitFor
and get the process result (Note that this will block your current Thread until the process has ended).
public int runCommand(String command) throws IOException
{
int returnValue = -1;
try {
Process process = Runtime.getRuntime().exec( command );
process.waitFor();
returnValue = process.exitValue();
} catch (InterruptedException e) {
e.printStackTrace();
}
return returnValue;
}