Friday, April 25, 2008

Return code

- In Java, invoke a sub-process


Process p = Runtime.getRuntime().exec(cmd);

Get the return code by p.waitFor() (not p.exitValue() which is not block-waiting and may get Exception). See this article for details.

- Return code in Java program
System.exit(n) where n is the status code, by convention, a nonzero status code indicates abnormal termination. It is different from the return value by method, which is returned to JVM. The exit code is returned from JVM to the machine.

- Check and return code in DOS batch
# invoke a java program ..
# check the program's exit code and abort with return code 2 (or we can log it), which will be digested
# by the caller of this batch file, e.g. C++ code in installer shield
if ERRORLEVEL 2 exit 2

The IF ERRORLEVEL n test succeeds if the error level is n or more.
See: ERRORLEVEL is not %ERRORLEVEL%

No comments: