home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name pcdoscmd -- Execute a DOS command
- *
- * Synopsis ercode = pcdoscmd(pcmd);
- *
- * int ercode Returned error code
- * char *pcmd Command to execute
- *
- * Description PCDOSCMD invokes a secondary copy of the command
- * processor to load and execute a DOS command. If the
- * command processor cannot be found, an error is returned.
- *
- * Method The function getenv() returns the COMSPEC= parameter,
- * which gives the path name for the command processor.
- * The command processor is loaded by by PCEXEC, passing
- * pcmd as the command line.
- *
- * Returns ercode Returned status code. Values
- * between -18 and 18 are codes returned
- * from PCEXEC. Other values are:
- * 19 - COMSPEC= could not be found in
- * the environment. This is an error
- * returned from getenv().
- * 20 - Command processor could not be found
- * 300 - Insufficient memory for scratch
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1983,1984,1986
- *
- **/
-
- #include <stdlib.h>
- #include <string.h>
-
- #include <bdirect.h>
- #include <bprogctl.h>
- #include <butility.h>
-
- #if MSC300
- #include <malloc.h>
- #endif
-
- #define OUT_OF_MEMORY 300
-
- int pcdoscmd(pcmd)
- char *pcmd;
- {
- char *pcomspec,*pdoscmd;
- int ercode;
-
- pcomspec = getenv("COMSPEC");
- if (pcomspec == NIL)
- return(19); /* Problem with the environment */
-
- if (NIL == (pdoscmd = calloc(4 + (int) strlen(pcmd),1)))
- return(OUT_OF_MEMORY);
- strcat(pdoscmd,"/C ");
- strcat(pdoscmd,pcmd);
-
- ercode = pcexec(pcomspec,pdoscmd,1);
-
- if (ercode == 2) /* "File not found" */
- ercode = 20; /* Can't find COMMAND.COM */
-
- free(pdoscmd);
-
- return(ercode);
- }