Search code examples
javaout-of-memoryprocessbuilder

Finding out if processbuilder generated process threw exception or finished cleanly


I am developing a program in Java that uses processbuilder to start another java program, so far I have no problems getting the other program to run, however I need to find out if the other program exited cleanly or threw an exception (Specifically I am looking for a java.lang.OutOfMemoryError). Putting the process.start() itself in a Try Catch block does not work, as I am never entering the catch block, even in cases when I am sure the child process threw an exception. Is there any way to check for this?


Solution

  • The Process you start will return an exit code. You can get it by calling

    process.exitValue()
    

    In the Java program you run you need to do System.exit(int_here) to indicate what happened. 0 means no error normally, but you're free to not follow any standards and make your own exit codes.