[an error occurred while processing this directive]

HP OpenVMS Systems

ask the wizard
Content starts here

» close window

The Question is:

 
I'm trying to obtain the "string equivalent" of the return value when using
the system() function in C.
 
The section of code looks as follows:
source & dest are pointers to char arrays.
 
        sprintf(copyCommand, "copy %s %s", source, dest);
        fflush(NULL);
        retVal = system(copyCommand);
        if(retVal > 1)
        {
            retVal = sys$getmsg(retVal, &errLen, &errDesc, errMsgFlg,
errMsgInfo);
            memset(dest, 0, strlen(dest));
            strcpy(dest, errMsg);
            return FALSE;
        }
 
When I run the previous with a purposely bad dest, sys$output receives the
following:
%COPY-E-OPENOUT, error opening POSSYS"possys
password"::$DISK2:[POSSYS.POSSCN]DEST.TXT; as output
-RMS-E-DNF, directory not found
-SYSTEM-W-NOSUCHFILE, no such file
 
Using the sys$getmsg above only returns "error opening !AS as output".  Do
you know of a way that I can get the entire error message that sys$output
gets (without having to force it into a file then read it).  I would like to
capture the error message int
o a char array that I can pass back to the caller.
 
Any information that you could provide me with would be great.
 
 


The Answer is :

Unfortunately, there is no way that this Wizard is aware of that you can get the
full error message (e.g., using $getmsg) from within the calling process.  The
return status from the system() function contains only the primary error code
(there really isn't room for anything more), and so all you can get is the
"%COPY-E-OPENOUT" message, with no arguments or chained conditions.
 
The output that you are seeing on SYS$OUTPUT is produced by the subprocess,
which obviously has access to the full information regarding the error.
 
There are several ways of dealing with trying to capture the error message,
depending on your requirements.  One would be to use LIB$SPAWN instead of
system(), and to set up a mailbox for the spawned process's output; this would
allow the spawning process to read the output without dealing with capturing it
in a file.  (This is the equivalent of setting up a pipe on Unix.)
 
Another possibility, if indeed what you're trying to do is a simple file copy,
is to do the copy operation yourself, using RMS services.  In this instance,
should the open fail, you would have all of the various statuses and arguments
available, for your call(s) to $getmsg.  (Note, this Wizard would recommend
using $putmsg with an "action routine" rather than $getmsg, as this would allow
you to format the whole chain of messages in a single call, and you can use the
action routine to capture the message text instead of having it printed to the
output.)

answer written or last revised on ( 8-OCT-1998 )

» close window