process.waitFor();
int exitCode = process.exitValue();
if(exitCode == 0) { // success }
else { // failed }
This works, if the Test
is designed properly and returns appropriate exit codes (generally, >0 if something went wrong).
If you want to get Test
s output/error message to determine what was wrong, you should get proc.getInputStream()
(this returns the output stream of the child process), proc.getErrorStream()
and read from the input streams in separated threads.
Note that the child process will get blocked if it writes to error/output stream and there are no readers. So reading error/output streams of the process is useful in any cases.
Another option to avoid child blocking is to redirect its error/output to a file and/or to /dev/null
('NUL' for windows):
Runtime.exec("java Test >/dev/null 2>&1");
Runtime.exec("java Test >/dev/null 2>erroroutput");