home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!ucbvax!lrw.com!leichter
- From: leichter@lrw.com (Jerry Leichter)
- Newsgroups: comp.os.vms
- Subject: RE: LIB$SPAWN
- Message-ID: <9208221447.AA26491@uu3.psi.com>
- Date: 22 Aug 92 13:58:18 GMT
- Sender: daemon@ucbvax.BERKELEY.EDU
- Distribution: world
- Organization: The Internet
- Lines: 61
-
-
- Would a kind soul explain to me why in the following code, a
- subprocess is spawned, a sort is started, but the names of the input
- and output files are not passed. Sort comes back to you and asks for
- them.
-
- ----------------------------------------------------
- #include stdio
- #include descrip
- #include ssdef
-
- void spawn( char *DCL_command );
-
- main(){
- char *DCL_command;
-
- DCL_command = "sort data.PCSA data.sort";
- printf( "%s", DCL_command );
- spawn( DCL_command );
- }
-
- void spawn( char *DCL_command )
- {
- int status;
-
- $DESCRIPTOR( command , DCL_command );
- if ((( status=LIB$SPAWN( &command )) & 1 ) != 1 )
- LIB$STOP( status );
- }
-
- This one is subtle, and actually quite amusing. The problem is a misuse of
- $DESCRIPTOR. $DESCRIPTOR is intended to create COMPILE-TIME descriptors -
- it's a declaration, not an executable statement. Here's its definition:
-
- #define $DESCRIPTOR(name,string) \
- struct dsc$descriptor_s name = \
- { sizeof(string)-1, /* String length */ \
- DSC$K_DTYPE_T, /* Type text */ \
- DSC$K_CLASS_S, /* Class string */ \
- string /* -> data */ \
- }
-
- (I've edited the definition for readability and added the comments.)
-
- The intent is that the string parameter be a quoted string; then, sizeof
- applied to it will produce the string's length, including the trailing NUL
- (so we subtract 1 and get the length of the actual string).
-
- In your case, string is the (char *) point DCL_command. sizeof applied to
- it produces the size of the POINTER, not of the string it points to, so the
- descriptor you produce always has length 3 (and, in this example, value
- "sor"). Since "SOR" is a valid abbreviation for SORT on your system, you
- do indeed manage to run SORT - but without any arguments.
-
- You need to set the string length to strlen(DCL_command). Unfortunately,
- that can't be done by this or any similar macro, since the fields of a
- structure initializer must be compile-time constants, and function calls
- don't qualify. You have to write some code to do it....
-
- -- Jerry
-
-