|
I used to use system() and thought the ease of using it was delightful. However there is an item that got be back to qcmdexc. The error handling. Don't get me wrong, system() has some error handling that will work for a majority of the time. Sample usage. I have /INCLUDE ROUTINES/QAPISRC,SYSTEM which contains * Execute Command (system) Subprocedure Variables D System PR 10I 0 ExtProc('system') D CmdText * Value Options(*String) Command text string D ErrorCPF S 7A Import('_EXCP_MSGID') Error number D ErrorFlag S 10I 0 Inz(0) Error flag and in my usage I may have: C Eval ErrorCPF=Blanks C C Eval ErrorFlag=system(cmd) C If ErrorFlag<>0 C Select C When ErrorCPF='CPF1111' C* ... C When ErrorCPF='CPF2222' C* ... C Other C* ... C EndSL C EndIf Now, that's not bad. But, getting back to qcmdexc. The problem is that I couldn't see the error message data. For example if CPF1111 had the name of an object that it couldn't manipulate there was no way to access that with system(). So I have: /INCLUDE ROUTINES/QRPGLESRC,PSDS which contains DMYPSDS SDS D PROC_NAME *PROC * Procedure name D PGM *PROC Program name D PGM_STATUS *STATUS * Status code D PRV_STATUS 16 20S 0 * Previous status D LINE_NUM 21 28 * Src list line num D ROUTINE *ROUTINE * Routine name D PARMS *PARMS * Num passed parms D EXCP_MSG 40 46 D EXCP_TYPE 40 42 * Exception type D EXCP_NUM 43 46 * Exception number D PGM_LIB 81 90 * Program library D EXCP_DATA 91 170 * Exception data D EXCP_ID 171 174 * Exception Id D PGM_DATE 191 198 * Date (*DATE fmt) D PGM_YEAR 199 200S 0 * Year (*YEAR fmt) D LAST_FILE 201 208 * Last file used D FILE_INFO 209 243 * File error info D JOB_NAME 244 253 * Job name D WSID 244 253 Workstation ID D USER 254 263 * User name D JOB_NUM 264 269S 0 * Job number D JOB_NUMA 6A overlay(JOB_NUM) * Job number, alpha D JOB_DATE 270 275S 0 * Date (UDATE fmt) D RUN_DATE 276 281S 0 * Run date (UDATE) D RUN_TIME 282 287S 0 * Run time (UDATE) D CRT_DATE 288 293 * Create date D CRT_TIME 294 299 * Create time D CPL_LEVEL 300 303 * Compiler level D SRC_FILE 304 313 * Source file D SRC_LIB 314 323 * Source file lib D SRC_MBR 324 333 * Source file mbr D PROC_PGM 334 343 * Pgm Proc is in D PROC_MOD 344 353 * Mod Proc is in call qcmdexc(parm:parmlen); // at this point you can check the psds fields for error // PSDS = Program Status Data Structure - look it up Select; When excp_id=*blanks; // ok // ok When excp_id='CPF1234'; // SAMPLE Select; When %subst(excp_data:1:10)='MYLIB'; // Do this or that EndSl; Other; EndSl; If you want to get really detailed with command execution, like maybe prompting a command before executing it, and much more, check out the api QCAPCMD. Rob Berendt -- Group Dekko Services, LLC Dept 01.073 PO Box 2000 Dock 108 6928N 400E Kendallville, IN 46755 http://www.dekko.com
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.