process.waitFor(); int exitCode = process.exitValue(); if(exitCode == 0) { // success } else { // failed }
This works if Test designed correctly and returns the appropriate exit codes (typically> 0 if something went wrong).
If you want to receive the Test output / error message to determine what is wrong, you should get proc.getInputStream() (this returns the output stream of the child process), proc.getErrorStream() and read from the input streams in split streams.
Note that the child process will be blocked if it writes to the error / output stream and there are no readers. Thus, the read / output streams of a process are useful anyway.
Another option to avoid blocking for children is to redirect their 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");
source share