home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / SNIP9404.ZIP / SHEL2DOS.C < prev    next >
C/C++ Source or Header  |  1994-04-03  |  1KB  |  51 lines

  1. /*
  2. **  SHEL2DOS.C - Shell to DOS from a running program
  3. **
  4. **  Original Copyright 1989-1991 by Bob Stout as part of
  5. **  the MicroFirm Function Library (MFL)
  6. **
  7. **  This subset version is hereby donated to the public domain.
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <process.h>
  14.  
  15. int shell_to_DOS(void)
  16. {
  17.       char *comspec, prompt[256], *oldprompt;
  18.       int retval;
  19.  
  20.       comspec = getenv("COMSPEC");
  21.       if(comspec == NULL)
  22.             comspec = "COMMAND.COM";     /* Better than nothing... */
  23.  
  24.       sprintf(prompt, "PROMPT=[Type EXIT to return to program]\r\n%s",
  25.             oldprompt = getenv("PROMPT"));
  26.       putenv(prompt); 
  27.  
  28.       retval = spawnlp(0, comspec, comspec, NULL);
  29.  
  30.       sprintf(prompt, "PROMPT=%s", oldprompt);
  31.       putenv(prompt);
  32.  
  33.       return retval;
  34. }
  35.  
  36. #ifdef TEST
  37.  
  38. #include <stdio.h>
  39.  
  40. void main(void)
  41. {
  42.       int retval = shell_to_DOS();
  43.  
  44.       printf("shell_to_DOS() returned %d\n", retval);
  45.  
  46.       retval = shell_to_DOS();
  47.       printf("shell_to_DOS() returned %d\n", retval);
  48. }
  49.  
  50. #endif
  51.