Hello Phil,

You wrote:
>> sprintf(buffer,_format_an_invalid_CL_command);
>> rc = system(buffer);
>> if(rc != 0)
>> {
>>   printf("Error is %s\n",_EXCP_MSGID);
>>   exit(-1);
>> }
>system() doesn't work like that.

Actually, system() does work like that.

>system() runs a 'self contained' task, the control boundary for it means
>that the any CPF msgs generated by it are 'out of scope' when system()
>returns control to you. If you want to be able to retrieve the CPF msgs,
>use QCAPCMD API instead of the system() runtime function.

That's true as far as it goes, however system() does set the _EXCP_MSGID
variable to point to a string containing the message ID of the error
message.  While this is not as useful as retrieving the message description
it does allow error handlig to branch according to the received error.

I modified Srikanth's example to create a working program.


int rc;
char buffer[100];

sprintf(buffer, "_format_an_invalid_CL_command");
rc = system(buffer);
if(rc != 0)
  printf("Error is %s\n",_EXCP_MSGID);

return 0;

Running it on my 440 system results in the expected behaviour.  For

Error is CPF0006
Press ENTER to end terminal session.

Simon Coulter.
   FlyByNight Software         AS/400 Technical Specialists

   Phone: +61 3 9419 0175   Mobile: +61 0411 091 400        /"\
   Fax:   +61 3 9419 0175   mailto: shc@flybynight.com.au   \ /
                 ASCII Ribbon campaign against HTML E-Mail  / \

This thread ...

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 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].