Running an IBM PASE for i program with QP2SHELL()

You use QP2SHELL or QP2SHELL2 programs to run an PASE for i program from any IBM® i command line and within any high-level language program, batch job, or interactive job.

These programs run an PASE for i program in the job that calls it. The name of the PASE for i program is passed as a parameter on the program.

The QP2SHELL() program runs the PASE for i program in a new activation group. The QP2SHELL2() program runs in the caller's activation group.

Note: Neither the QP2SHELL program nor the QP2SHELL2 program does the special setup for standard streams that most shells require for reliable operation (stdin, stdout, and stderr must be forkable file descriptors). Therefore, the QP2SHELL and QP2SHELL2 programs must be used with additional programming to run a shell or shell script. You can run a shell script without additional programming by using either the API program QP2TERM or the QSH CL command.

The following example runs the ls command from the IBM i command line:

call qp2shell parm('/QOpenSys/bin/ls' '/')

If you pass values into QP2SHELL() using CL variables, the variables must be null-terminated. For example, you need to code the above example in the following way:

PGM  DCL  VAR(&CMD)    TYPE(*CHAR)   LEN(20)    VALUE('/QOpenSys/bin/ls')
DCL  VAR(&PARM1)  TYPE(*CHAR)   LEN(10)    VALUE('/')
DCL  VAR(&NULL)   TYPE(*CHAR)   LEN(1)     VALUE(X'00')

                   CHGVAR VAR(&CMD) VALUE(&CMD *TCAT &NULL)
                   CHGVAR VAR(&PARM1) VALUE(&PARM1 *TCAT &NULL)

                   CALL PGM(QP2SHELL) PARM(&CMD &PARM1)
    
ENDIT:
ENDPGM