home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / PCDOSCMD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  1.7 KB  |  69 lines

  1. /**
  2. *
  3. * Name        pcdoscmd -- Execute a DOS command
  4. *
  5. * Synopsis    ercode = pcdoscmd(pcmd);
  6. *
  7. *        int  ercode      Returned error code
  8. *        char *pcmd      Command to execute
  9. *
  10. * Description    PCDOSCMD invokes a secondary copy of the command
  11. *        processor to load and execute a DOS command.  If the
  12. *        command processor cannot be found, an error is returned.
  13. *
  14. * Method    The function getenv() returns the COMSPEC= parameter,
  15. *        which gives the path name for the command processor.
  16. *        The command processor is loaded by by PCEXEC, passing
  17. *        pcmd as the command line.
  18. *
  19. * Returns    ercode          Returned status code.  Values
  20. *                  between -18 and 18 are codes returned
  21. *                  from PCEXEC.    Other values are:
  22. *                  19 - COMSPEC= could not be found in
  23. *                       the environment.  This is an error
  24. *                       returned from getenv().
  25. *                  20 - Command processor could not be found
  26. *                  300 - Insufficient memory for scratch
  27. *
  28. * Version    3.0 (C)Copyright Blaise Computing Inc.    1983,1984,1986
  29. *
  30. **/
  31.  
  32. #include <stdlib.h>
  33. #include <string.h>
  34.  
  35. #include <bdirect.h>
  36. #include <bprogctl.h>
  37. #include <butility.h>
  38.  
  39. #if MSC300
  40. #include <malloc.h>
  41. #endif
  42.  
  43. #define OUT_OF_MEMORY    300
  44.  
  45. int pcdoscmd(pcmd)
  46. char *pcmd;
  47. {
  48.     char   *pcomspec,*pdoscmd;
  49.     int    ercode;
  50.  
  51.     pcomspec = getenv("COMSPEC");
  52.     if (pcomspec == NIL)
  53.        return(19);              /* Problem with the environment */
  54.  
  55.     if (NIL == (pdoscmd = calloc(4 + (int) strlen(pcmd),1)))
  56.     return(OUT_OF_MEMORY);
  57.     strcat(pdoscmd,"/C ");
  58.     strcat(pdoscmd,pcmd);
  59.  
  60.     ercode = pcexec(pcomspec,pdoscmd,1);
  61.  
  62.     if (ercode == 2)              /* "File not found"             */
  63.     ercode = 20;              /* Can't find COMMAND.COM       */
  64.  
  65.     free(pdoscmd);
  66.  
  67.     return(ercode);
  68. }
  69.