Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!mit-eddie!uw-beaver!tektronix!teklds!copper!stevesu From: stevesu@copper.UUCP Newsgroups: comp.os.vms Subject: Re: Why no system() under VAX C Message-ID: <1106@copper.TEK.COM> Date: Wed, 10-Jun-87 00:56:06 EDT Article-I.D.: copper.1106 Posted: Wed Jun 10 00:56:06 1987 Date-Received: Sat, 13-Jun-87 03:45:04 EDT References: <12308535119.47.AWALKER@RED.RUTGERS.EDU> <552@unc.cs.unc.edu> <3322@sri-unix.ARPA> Distribution: na Organization: Tektronix Inc., Beaverton, Or. Lines: 65 Summary: here's one In article <3322@sri-unix.ARPA>, ubi@sri-unix.ARPA (Ron Ueberschaer) writes: > Speaking of glaring, why did DEC decide not to implement system() > under VMS??? It's bad enough that I can't exec anything except > C programs. I suspect they left it out because you probably don't want to use it. The only way to implement system() is with lib$spawn(), which is notoriously slow. Here's one I use, which I call "vmssystem" so that I have to think about it before using it. (A program containing "system" won't automatically link, without some attention.) Besides thinking about whether you can afford to spend several seconds in a lib$spawn, you may also need to change the string actually passed to system(), which is usually a Unix command of some sort. (For example, just because you had a working "system" wouldn't mean that you could port the tar utility, which contains this gem: sprintf(buf, "sort +0 -1 +1nr %s -o %s; \ awk '$1 != prev {print; prev=$1}' %s >%sX; mv %sX %s", tname, tname, tname, tname, tname, tname); system(buf); Steve Summit stevesu@copper.tek.com #define NULL 0 struct descriptor { short dsc_length; char dsc_type; char dsc_class; char *dsc_addr; }; vmssystem(command) char *command; { int r; long int status; struct descriptor vmscmd; vmscmd.dsc_addr = command; vmscmd.dsc_length = strlen(command); vmscmd.dsc_type = vmscmd.dsc_class = 0; r = lib$spawn(&vmscmd, /* command string */ (struct descriptor *)NULL, /* input file */ (struct descriptor *)NULL, /* output file */ (long int *)NULL, /* flags */ (struct descriptor *)NULL, /* process name */ (long int *)NULL, /* process id */ &status, /* completion status */ (unsigned char *)NULL, /* completion efn */ (int (*)())NULL, /* completion astadr */ 0, /* completion astarg */ (struct descriptor *)NULL, /* prompt */ (struct descriptor *)NULL); /* CLI */ if(!(r & 01)) return -1; return status; }