× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Kelly Jones wrote:
We have a situation where we need to call a Java program, have it do
"it's thing", then pass a return code back to the calling program.  The
main point of the return code is to inform the calling program whether
everything went OK.  If the Java program bombs, we need to inform the
caller that something bad happened and stop.
Can someone provide an example how to do this?

If you could have your Java program throw an exception instead of using a return code, the CL or RPG program could use the JAVA command (RUNJVA is another name for this command), and monitor for the JVA0122 message that is issued if it ends with a thrown exception.

class jcombine
{
    static public void main(String args[])
       throws Exception
    {
       if (args.length < 1
       ||  args[0].equals("crash"))
       {
          throw new Exception ("no args, or arg=crash");
       }
    }
}

You could set the classpath using the CLASSPATH environment variable, instead of using the parameter on the RUNJVA command.

A CL program using RUNJVA:

   RUNJVA jcombine OUTPUT(*PRINT) CLASSPATH('x')
   MONMSG JVA0122 EXEC(SNDPGMMSG 'failed, no args')

   RUNJVA jcombine PARM('crash') OUTPUT(*PRINT) CLASSPATH('x')
   MONMSG JVA0122 EXEC(SNDPGMMSG 'failed, arg="crash"')

   RUNJVA jcombine parm('hello') OUTPUT(*PRINT) CLASSPATH('x')
   SNDPGMMSG 'no error, arg="hello"'

My joblog after running this CL program:

   Java program completed with exit code 1
   failed, no args
   Java program completed with exit code 1
   failed, arg="crash"
   no error, arg="hello"


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.