Return codes from PASE to i5/OS - IBM AS400

This is a discussion on Return codes from PASE to i5/OS - IBM AS400 ; I am calling a shell script with QP2SHELL2. I'd like the shell script to set the return code via return, and use RTVJOBA RTNCDE() to retrieve it in i5/OS, as suggested by an earlier poster. That doesn't seem to work ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Return codes from PASE to i5/OS

  1. Return codes from PASE to i5/OS

    I am calling a shell script with QP2SHELL2. I'd like the shell script
    to set the return code via return, and use RTVJOBA RTNCDE() to retrieve
    it in i5/OS, as suggested by an earlier poster. That doesn't seem to
    work on V5R4:

    #!/QOpenSys/usr/bin/sh
    # the intent here is to set a return code in ILE
    echo "$0" is running...
    return 1

    > /home/buck/pasetest

    /home/buck/pasetest is running...
    $
    > echo $?

    1
    $

    pgm
    dcl &rtncde *dec (5 0)
    dcl &cmd *char 64
    dcl &null *char 1 value(x'00')
    chgvar &cmd ('/home/buck/pasetest' *cat &null)
    call qp2shell2 (&cmd)
    rtvjoba rtncde(&rtncde)
    dmpclpgm
    endpgm

    &RTNCDE is zero.

    So I tried adding a C program into the mix:

    /* Test PASE return code */
    int main ()
    {
    return(5);
    }

    > ./pasectest

    $
    > echo $?

    5
    $

    chgvar &cmd ('/home/buck/pasectest' *cat &null
    call qp2shell2 (&cmd)

    ....and again RTNCDE is zero.

    The docs for QP2SHELL say that QP2SHELL doesn't return a value, but it
    doesn't appear to set the job attribute RTNCDE either. My intention is
    to have a shell script tell my CL program whether everything ran OK on
    the PASE side or not.

    Thanks!
    --buck


  2. Re: Return codes from PASE to i5/OS

    "Buck" wrote in message
    news:1162916798.085672.138860@m73g2000cwd.googlegr oups.com...
    >I am calling a shell script with QP2SHELL2.


    Probably an "iffy" proposition. Shells don't work reliably unless they run
    in an environment that has forkable descriptors for stdin/out/err.
    QP2SHELL2 (and QP2SHELL) uses ILE C runtime support for stdin/out/err, which
    doesn't produce/use true forkable descriptors, so any process the shell
    forks will be a batch job that uses spool files for stdin/out/err (probably
    not what you want).

    You can use QP2TERM or run the QSH command to start an environment with
    forkable stdin/out/err descriptors. (QSH can be used to run any i5/OS PASE
    program, including an i5/OS PASE shell if you want/need one to run your
    script)

    > The docs for QP2SHELL say that QP2SHELL doesn't return a value, but it
    > doesn't appear to set the job attribute RTNCDE either.


    QP2SHELL and QP2SHELL2 both use ILE C runtime to set the job attribute.
    Both are ILE C++ programs that use this idiom to set the return code:

    int main(int argc, char **argv)
    {
    int rc = Qp2RunPase(...); // rc contains process exit status value
    return WEXITSTATUS(rc); // extracts 8-bit exit statue from rc
    }

    The fact that the return code is set can be observed by running an i5/OS
    PASE program from a QShell command line (QShell calls QP2SHELL to run an
    i5/OS PASE program):

    > /QOpenSys/usr/bin/cmp filea filea_dupe ; echo $?

    0
    $
    > /QOpenSys/usr/bin/cmp filea not_filea ; echo $?

    filea not_filea differ: char 9, line 2
    1
    $

    --
    George Timms
    IBM Rochester



  3. Re: Return codes from PASE to i5/OS

    Hi George!

    First, thanks for the very informative response. Seeing the internal
    prototypes helps.

    > >I am calling a shell script with QP2SHELL2.

    >
    > Probably an "iffy" proposition.


    Thanks for this. I should have known better. In my case I got lucky
    because I'm not using stdin/out/err.

    > QP2SHELL and QP2SHELL2 both use ILE C runtime to set the job attribute.

    -snip-
    > The fact that the return code is set can be observed by running an i5/OS
    > PASE program from a QShell command line (QShell calls QP2SHELL to run an
    > i5/OS PASE program):
    > > /QOpenSys/usr/bin/cmp filea not_filea ; echo $?

    > filea not_filea differ: char 9, line 2
    > 1
    > $


    I see that behaviour here as well. Using your example above:

    > qsh cmd('/QOpenSys/usr/bin/cmp filea not filea')

    Command ended normally with exit status 2.

    dspjob:
    Program return code . . . . . . . . . . . . : 0

    RTVJOBA RTNCDE() shows a value of 0.

    Here is working code:

    pgm
    dcl &rtncde *dec ( 5 0)
    dcl &rtndec *dec (10 0)
    dcl &cmd *char 64
    dcl &msgid *char 7
    dcl &msgdta *char 4
    chgvar &cmd ('/home/buck/pasetest')
    qsh cmd(&cmd)
    rtvjoba rtncde(&rtncde)
    rcvmsg msgtype(*comp) rmv(*no) +
    msgdta(&msgdta) msgid(&msgid)
    if (&msgid *eq 'QSH0005') +
    chgvar &rtndec %bin(&msgdta)
    dmpclpgm
    endpgm

    The script:
    #!/QOpenSys/usr/bin/sh
    # the intent here is to set a return code back in ILE
    rc=10
    echo "return will be $rc"
    exit $rc

    RTVJOBA RTNCDE() is always zero, but receiving the QSH0005 tells me the
    return code of the script. As an additional note, the script works
    whether exit or return is used. Apparently, the intent of RTVJOBA
    RTNCDE() is to report the status of the QSH or QP2SHELL calls and not
    the scripts/programs they execute.

    I'll send a note to the documentation team to help clarify this.

    Thanks for your help. I'd never have thought of firing my PASE scripts
    via QSH on my own.
    --buck


  4. Re: Return codes from PASE to i5/OS

    It seems the way to obtain the return code from an ILE program (including
    QP2SHELL or QP2SHELL2) is by using the "User Return Code" field in the
    JOBI0600 format returned by the QUSRJOBI API. As you've observed, RTVJOBA
    RTNCDE won't get you the return code from an ILE program.

    Here is a little (V5R4) CL program to demonstrate:

    PGM
    DCL &JOBI0600 *CHAR 112
    DCL &JOBILEN *INT 4 VALUE(112)
    DCL &ILERC *INT 4 STG(*DEFINED) DEFVAR(&JOBI0600 109)

    CALL SOMEILEPGM

    CALL PGM(QUSRJOBI) PARM(&JOBI0600 &JOBILEN 'JOBI0600' +
    '* ' +
    ' ')
    DMPCLPGM
    ENDPGM

    The "CALL SOMEILEPGM" line could be replaced with the "call qp2shell2
    (&cmd)" statement from the original post (assuming George Timms' excellent
    points regarding shells and forkable stdin/out/err descriptors do not
    apply).

    --
    -----
    Walt Madden - IBM System i software development



+ Reply to Thread