H NOMAIN *T: Command processing * *O: CRTRPGMOD DBGVIEW(*SOURCE) CVTOPT(*DATETIME) OPTION(*NODEBUGIO) * *C: CRTSRVPGM OPTION(*DUPVAR *DUPPROC *NOWARN) EXPORT(*ALL) + *C: SRVPGM(&L/&N1S) MODULE(&N) BNDDIR(QC2LE) + *C: TEXT('Command processing') * *C: ADDBNDDIRE BNDDIR(QGPL/UTILITY) OBJ((&L/&N1S *SRVPGM)) * *‚SYNOPSIS: This module includes the cl() procedure. This procedure *‚ is a wrapper to the QCAPCMD API, to allow the user to *‚ execute a command. An optional error parameter can be *‚ passed. * *===================================================================== D/COPY QRPGLESRC,CMDPRC_P ‚Command processing * D qcapcmd PR Extpgm('QCAPCMD') D SrcStr 32702A Const Options(*Varsize) D SrcStrLen 10I 0 Const D CPOP0100 20A Const D CPOP0100Len 10I 0 Const D Format 8A Const D RtnStr 32702A Options(*Varsize) D RtnStrAvlLen 10I 0 Const D RtnStrRtnLen 10I 0 D QUSEC Like(QUSEC_T) * D CPOP0100 DS Qualified D CmdPrcType 10I 0 Inz(0) D HandleDBCS N Inz(*on) D PromptAction 1A Inz('0') D UseS38Syntax N Inz(*off) D MsgRtvKey 10I 0 Inz(0) D 9A Inz(*allx'00') * D system PR 10I 0 extproc('system') D string@ * value options(*string) * *===================================================================== *‚cl(): Executes a command. Returns 0 if it ran successfully or 1 if *‚ it failed. If an optional error structure is passed, errors *‚ are returned in it rather than written to the job log. *===================================================================== P cl B Export D PI 10I 0 D CmdStr@ * Value Options(*String) D P_QUSEC Like(QUSEC_T) Options(*Nopass) *--------------------------------------------------------------------- D QUSEC DS Likeds(QUSEC_T) Inz(*Likeds) D CmdStr S 32702A D RtnStr S Inz Like(CmdStr) D RtnStrLen S 10I 0 Inz *--------------------------------------------------------------------- /free //‚Simply use the system() procedure if a single parameter passed if %parms = 1; return system( CmdStr@ ); endif; //‚Set parameters and call QCAPCMD API. CmdStr = %str( CmdStr@ ); reset CPOP0100; CPOP0100.PromptAction = ( %subst( CmdStr : 1 : 1 ) = '?' ); reset QUSEC; qcapcmd( CmdStr : %len( CmdStr ) : CPOP0100 : %len( CPOP0100 ) : 'CPOP0100' : RtnStr : %len( RtnStr ) : RtnStrLen : QUSEC ); if QUSEC.ErrBytesAvail > 0; exsr *pssr; endif; //‚Return errors in the P_QUSEC parameter. P_QUSEC = QUSEC; return 0; begsr *pssr; if %parms > 1; P_QUSEC = QUSEC; endif; return 1; endsr; /end-free P E