Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ucbvax!YALE.ARPA!LEICHTER-JERRY From: LEICHTER-JERRY@YALE.ARPA.UUCP Newsgroups: comp.os.vms Subject: Re: Why no system() under VAX C Message-ID: <8706110006.AA11239@ucbvax.Berkeley.EDU> Date: Wed, 10-Jun-87 20:07:00 EDT Article-I.D.: ucbvax.8706110006.AA11239 Posted: Wed Jun 10 20:07:00 1987 Date-Received: Sat, 13-Jun-87 05:30:39 EDT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Distribution: world Organization: The ARPA Internet Lines: 105 ... Speaking of glaring [failures to emulate Unix], why did DEC decide not to implement system() under VMS??? It's bad enough that I can't exec anything except C programs. I hate having to work under VMS, but if I could say system("@foo bare"); , or system("show time"); , or even system("run $disk:[mydir]foo"); , ... The purpose of VAX C's emulation of the Unix library is primarily to allow Unix code to be ported to VMS as easily as possible. Any Unix program that uses system() is applying it to a shell command, which isn't likely to work on VMS anyway. Besides, it's pretty easy to implement system() on top of LIB$SPAWN; I've included code below. Given the history of the VAX C RTL, which has picked up more and more Unix emulation functions as time has gone on, a version of system() could easily show up at some point - i.e., this could be simply a matter of implementation priorities. Should this happen, the enclosed code would become obsolete, and you should get rid of it. (Note that the VAX C RTL ships with VMS these days, so you have to watch the VMS release notes.) The code could be sped up (considerably), and still do what you usually want it to do, by including such flags as NOCLISYM and NOLOGNAM, thus eliminating the possibly long wait while DCL copies over all your defined symbols and process logicals. The current code, while slower, is more general, since it allows you to SPAWN commands you've defined in DCL. I'd stop complaining for a few hours, anyway. Amazing. A Unix programmer who'll stop complaining about VMS, even if only for a few hours. It's just because of that promise that I've enclosed this code.... :-) -- Jerry ---------------------------------Cut here------------------------------------- /*-----------------SYSTEM emulation------------------------------------- * * Executes the VMS DCL command in string command_line. * The command may ask the terminal for further input. * After the VMS command exits, control is returned to the calling * function. * * Example: * system("show def"); * * Beware: This call is painfully slow on a loaded system * * for VAX-VMS 4-Nov-85 J. Faricelli * modified 2-Dec-85 J. Faricelli (allow command to ask for input) * *----------------------------------------------------------------------*/ #include stdio.h int system(command_line) char *command_line; { #include descrip /* VMS descriptors header file */ #include ssdef /* VMS system call header file */ static $DESCRIPTOR(spawn_line,""); int lib$spawn(); int spawn_flags, spawn_rc, i; unsigned int len; char *string; /* Create local storage for command line */ len = strlen(command_line); string = (char *) malloc(len); strncpy(string,command_line,len); /* VMS doesn't grok a newline at the end of the string, so don't send that to spawn (make it a blank). */ /* command_line[len-1] is end of string (remember, index is 0..len-1) */ if ( command_line[len-1] == '\n' ) { string[len-1] = ' '; } /* Prepare descriptor for call to spawn */ spawn_line.dsc$w_length = len; spawn_line.dsc$a_pointer = string; spawn_flags = 0; spawn_rc = lib$spawn(&spawn_line,&0,&0,&spawn_flags); if( spawn_rc != SS$_NORMAL ) { fprintf(stderr,"Internal error in VMS emulation of system() call\n\ Error during spawn of subprocess:\n\ VMS return code was: %d\n",spawn_rc); free(string); return(-1); } free(string); return(0); } -------