home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / SHEL2DOS.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  1KB  |  57 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  SHEL2DOS.C - Shell to DOS from a running program
  5. **
  6. **  Original Copyright 1989-1991 by Bob Stout as part of
  7. **  the MicroFirm Function Library (MFL)
  8. **
  9. **  The user is granted a free limited license to use this source file
  10. **  to create royalty-free programs, subject to the terms of the
  11. **  license restrictions specified in the LICENSE.MFL file.
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <process.h>
  18. #include "snpdosys.h"
  19.  
  20. int shell_to_DOS(void)
  21. {
  22.       char *comspec, prompt[256], *oldprompt;
  23.       int retval;
  24.  
  25.       comspec = getenv("COMSPEC");
  26.       if(comspec == NULL)
  27.             comspec = "COMMAND.COM";     /* Better than nothing... */
  28.  
  29.       sprintf(prompt, "PROMPT=[Type EXIT to return to program]\r\n%s",
  30.             oldprompt = getenv("PROMPT"));
  31.       putenv(prompt); 
  32.  
  33.       retval = spawnlp(0, comspec, comspec, NULL);
  34.  
  35.       sprintf(prompt, "PROMPT=%s", oldprompt);
  36.       putenv(prompt);
  37.  
  38.       return retval;
  39. }
  40.  
  41. #ifdef TEST
  42.  
  43. #include <stdio.h>
  44.  
  45. main()
  46. {
  47.       int retval = shell_to_DOS();
  48.  
  49.       printf("shell_to_DOS() returned %d\n", retval);
  50.  
  51.       retval = shell_to_DOS();
  52.       printf("shell_to_DOS() returned %d\n", retval);
  53.       return 0;
  54. }
  55.  
  56. #endif /* TEST */
  57.