IBM Support

Simple Example Showing How To Call QP2SHELL In A CL Program

Question & Answer


Question

How can a UNIX command be run by using PASE in a CL program and provide output redirection?

Answer

There are a couple of things that have to be done to make this work correctly. First, in order to get redirection with QP2SHELL, you have to call it in the format:

CALL QP2SHELL('/QOpenSys/usr/bin/sh' '-c' 'command')

Second, to make that work in a CL program, you must null terminate each of the parameters to the QP2SHELL program. The following is a simple example that would replace all the instances of 'si' with 'is' in the file /test/aa1 and put the output in the file /test/aa2:


             PGM

             DCL        VAR(&CMD)    TYPE(*CHAR)   LEN(21) VALUE('/QOpenSys/usr/bin/sh')
             DCL        VAR(&PARM1)  TYPE(*CHAR)   LEN(10)    VALUE('-c')
             DCL        VAR(&PARM2)  TYPE(*CHAR)   LEN(65)    VALUE('/QOpenSys/usr/bin/sed +
                          "s/si/is/g" /test/aa1 > /test/aa2')
             DCL        VAR(&NULL)   TYPE(*CHAR)   LEN(1)     VALUE(X'00')

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

             CALL       PGM(QP2SHELL) PARM(&CMD &PARM1 &PARM2)

             ENDPGM

[{"Product":{"code":"SWG60","label":"IBM i"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":"Operating System","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"Version Independent","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}}]

Document Information

Modified date:
27 December 2019

UID

nas8N1022523