Re: Shelling out CRTLF via QCMDEXC -- question about success/failure
Jon Paris <[email protected]> Tue, 9 Jun 2026 12:28:24 -0400
| Newsgroups | gmane.comp.hardware.ibm.midrange |
|---|---|
| Message-ID | <[email protected]> |
Because very often the cause is not relevant, or occurs within such a small scope as to be irrelevant. If copying or creating a file do you really care if it failed because of a missing file or library? It only matters if you can programatically deal with it and try again. And since you have the CPF message number available, that is sufficiently granular to differentiate error cases. You don't need to be able to retrieve (for example) the library or file name - you already have them - after all you created the command. As I said, I use other options when I need more than system() will give me, but that does not happen that often. Jon Paris [email protected] > On Jun 9, 2026, at 12:19 PM, Birgitta Hauser <[email protected]> wrote: > > Most time I need to know: It did not work ... why? > > Mit freundlichen Grüßen / Best regards > > Birgitta Hauser > Modernization – Education – Consulting on IBM i > Database and Software Architect > IBM Champion since 2020 > > "Shoot for the moon, even if you miss, you'll land among the stars." (Les Brown) > "If you think education is expensive, try ignorance." (Derek Bok) > "What is worse than training your staff and losing them? Not training them and keeping them!" > "Train people well enough so they can leave, treat them well enough so they don't want to. " (Richard Branson) > "Learning is experience … everything else is only information!" (Albert Einstein) > > > -----Original Message----- > From: MIDRANGE-L <[email protected]> On Behalf Of Jon Paris > Sent: Tuesday, 9 June 2026 18:16 > To: Midrange Systems Technical Discussion <[email protected]> > Subject: Re: Shelling out CRTLF via QCMDEXC -- question about success/failure > > For me, I tend to use system() if I need to know what message caused the error, but don't care about the message text or substitution variables. > > That is probably 90%+ of all cases. > > I like system() because its intent is obvious (unlike the SQL examples) and easy to test for an error. Most times all you want is "did it work". > > > Jon Paris > [email protected] > > > >> On Jun 9, 2026, at 10:57 AM, Rob Berendt <[email protected]> wrote: >> >> I was a big fan of system(), until I was not. I forget why. Others >> have alluded to the ease of getting the error with QCAPCMD instead. >> Perhaps that was it. >> >> On Tue, Jun 9, 2026 at 8:35 AM Vern Hamberg via MIDRANGE-L < >> [email protected]> wrote: >> >>> Hi Birgitta >>> >>> Yes, the system() function returns an integer, 0 if the command is >>> successful. And, according to the reference, we have this - >>> >>>> If the system() function fails, the global variable _EXCP_MSGID in >>>> <stddef.h> is set with the exception message ID. >>> >>> *Regards* >>> >>> *Vern Hamberg* >>> >>> IBM Champion 2025 <cid:[email protected]> CAAC >>> (COMMON Americas Advisory Council) IBM Influencer 2023 >>> >>> >>> On 6/9/2026 1:53 AM, Birgitta Hauser wrote: >>>> Jon and AI >>>> >>>> How you'd get the CPF-Msg which is checked in the example if only an >>> error code is returned? ;) >>>> >>>> When using QCMDEXC it is possible to trap the system error message! >>>> >>>> Mit freundlichen Grüßen / Best regards >>>> >>>> Birgitta Hauser >>>> Modernization – Education – Consulting on IBM i Database and >>>> Software Architect IBM Champion since 2020 >>>> >>>> "Shoot for the moon, even if you miss, you'll land among the stars." >>> (Les Brown) >>>> "If you think education is expensive, try ignorance." (Derek Bok) >>>> "What is worse than training your staff and losing them? Not >>>> training >>> them and keeping them!" >>>> "Train people well enough so they can leave, treat them well enough >>>> so >>> they don't want to. " (Richard Branson) >>>> "Learning is experience … everything else is only information!" >>>> (Albert >>> Einstein) >>>> >>>> >>>> -----Original Message----- >>>> From: MIDRANGE-L<[email protected]> On Behalf Of >>> Jon Paris >>>> Sent: Monday, 8 June 2026 23:41 >>>> To: Midrange Systems Technical >>>> Discussion<[email protected]> >>>> Subject: Re: Shelling out CRTLF via QCMDEXC -- question about >>> success/failure >>>> >>>> Personally, I'd use the system() function. Much easier to test for >>> errors and determine the root failure message. >>>> >>>> Google's AI came up with this example whcih I have not tested but it >>> looks about right. >>>> >>>> **free >>>> // Modern control specifications—no bnddir('QC2LE') needed! >>>> ctl-opt dftactgrp(*no); >>>> >>>> // Prototype for the C system() function dcl-pr runCommand int(10) >>> extproc('system'); >>>> cmdString pointer value options(*string); end-pr; >>>> >>>> // Import system variable to capture error message IDs dcl-s >>>> errorMsg >>> char(7) import('_EXCP_MSGID'); >>>> >>>> // Variable to store the return code dcl-s returnCode int(10); >>>> >>>> // Execute a CL command directly >>>> returnCode = runCommand('CLRPFM FILE(MYLIB/MYFILE)'); >>>> >>>> // Check for execution failure >>>> if returnCode <> 0; >>>> if errorMsg = 'CPF3142'; // File not found >>>> // Handle specific error logic here >>>> endif; >>>> endif; >>>> >>>> *inlr = *on; >>>> >>>> >>>> Jon Paris >>>> [email protected] >>>> >>>> >>>> >>>>> On Jun 8, 2026, at 5:31 PM, James H. H. Lampert via MIDRANGE-L< >>> [email protected]> wrote: >>>>> >>>>> I've got a project in which I will be using a QCMDEXC call to shell >>>>> out >>> a CRTLF (from a generated source member). What is the easiest way for >>> the calling program to determine whether the CRTLF was successful? >>>>> >>>>> -- >>>>> JHHL >>>>> -- >>>>> This is the Midrange Systems Technical Discussion (MIDRANGE-L) >>>>> mailing list To post a message email:[email protected] >>>>> To subscribe, unsubscribe, or change list options, >>>>> visit:https://lists.midrange.com/mailman/listinfo/midrange-l >>>>> or email:[email protected] >>>>> Before posting, please take a moment to review the archives at >>>>> https://archive.midrange.com/midrange-l. >>>>> >>>>> Please [email protected] for any subscription >>> related questions. >>>>> >>>> -- >>>> This is the Midrange Systems Technical Discussion (MIDRANGE-L) >>>> mailing >>> list To post a message email:[email protected] To >>> subscribe, unsubscribe, or change list options, >>>> visit:https://lists.midrange.com/mailman/listinfo/midrange-l >>>> or email:[email protected] >>>> Before posting, please take a moment to review the archives >>>> athttps:// >>> archive.midrange.com/midrange-l. >>>> >>>> Please [email protected] for any subscription >>>> related >>> questions. >>>> >>>> >>> -- >>> This is the Midrange Systems Technical Discussion (MIDRANGE-L) >>> mailing list To post a message email: [email protected] >>> To subscribe, unsubscribe, or change list options, >>> visit: https://lists.midrange.com/mailman/listinfo/midrange-l >>> or email: [email protected] >>> Before posting, please take a moment to review the archives at >>> https://archive.midrange.com/midrange-l. >>> >>> Please contact [email protected] for any subscription >>> related questions. >>> >>> >> -- >> This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing >> list To post a message email: [email protected] To >> subscribe, unsubscribe, or change list options, >> visit: https://lists.midrange.com/mailman/listinfo/midrange-l >> or email: [email protected] >> Before posting, please take a moment to review the archives at >> https://archive.midrange.com/midrange-l. >> >> Please contact [email protected] for any subscription related questions. >> > > -- > This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: [email protected] To subscribe, unsubscribe, or change list options, > visit: https://lists.midrange.com/mailman/listinfo/midrange-l > or email: [email protected] > Before posting, please take a moment to review the archives at https://archive.midrange.com/midrange-l. > > Please contact [email protected] for any subscription related questions. > > > -- > This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list > To post a message email: [email protected] > To subscribe, unsubscribe, or change list options, > visit: https://lists.midrange.com/mailman/listinfo/midrange-l > or email: [email protected] > Before posting, please take a moment to review the archives > at https://archive.midrange.com/midrange-l. > > Please contact [email protected] for any subscription related questions. > -- This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: [email protected] To subscribe, unsubscribe, or change list options, visit: https://lists.midrange.com/mailman/listinfo/midrange-l or email: [email protected] Before posting, please take a moment to review the archives at https://archive.midrange.com/midrange-l. Please contact [email protected] for any subscription related questions.