IBM i Commands are normally run from a command line or from a CL program, but it is very simple to run the also from an RPG program.
The IBM i API program QCMDEXC is used for this. The API takes a string containing the command and the length of the command.
To simplify this in an RPG application a procedure can be made as a general utility where the call to the API is made.
Example of a procedure executing a supplied command
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
//---------------------------------------------------------------------- // Procedure Name: exec_Command // Description...: Executes requested command //---------------------------------------------------------------------- dcl-proc exec_Command; dcl-pi *n ind; Command char(512) const; end-pi ; dcl-pr QCMDEXC extpgm; *n char(512) options(*varsize) const; *n packed(15:5) const; end-pr; monitor ; QCMDEXC(Command:%len(%trimr(Command))); on-error; return *off; endmon; return *on; end-proc; |