home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / msdos / programm / 11951 < prev    next >
Encoding:
Text File  |  1993-01-09  |  1.6 KB  |  61 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!munnari.oz.au!bruce.cs.monash.edu.au!monu6!giaeb!s1110238
  3. From: s1110238@giaeb.cc.monash.edu.au (Lee Hollingworth)
  4. Subject: Re: question on spawning DOS from C prog
  5. Message-ID: <s1110238.726575527@giaeb>
  6. Sender: news@monu6.cc.monash.edu.au (Usenet system)
  7. Organization: Monash University, Melb., Australia.
  8. References: <1993Jan7.140524.15787@ns1.cc.lehigh.edu>
  9. Date: Sat, 9 Jan 1993 10:32:07 GMT
  10. Lines: 49
  11.  
  12. jmt7@ns1.cc.lehigh.edu (JOHN M. TROIANO) writes:
  13.  
  14. >In article <tim.36.726368023@tim.src.utah.edu>, tim@tim.src.utah.edu (Tim Ma) wr
  15. >ites:
  16.  
  17. >Hi, I am the original poster of this problem: this is especially to
  18. >Tim and Wolfgang. I tried the code below (which is I think what both
  19. >of you guys are suggesting) but it does'nt work (the new prompt
  20. >string is ignored). Any ideas?     - John.
  21.  
  22. I am neither Tim nor Wolfgang, but the following *does* work!
  23.  
  24. #include <process.h>
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27.  
  28. int shell(char *);
  29.  
  30. void main(void)
  31. {
  32.    static char *message = "PROMPT=Type EXIT to return to program $_$P$G ";
  33.  
  34.    if (shell(message) == -1) {
  35.       fprintf(stderr, "Error: cannot shell to DOS\n");
  36.    }
  37. }
  38.  
  39. /***
  40.  * function: shell
  41.  * purpose:  shell out to DOS operating system.
  42.  * passed:   prompt -- prompt to be displayed in DOS environment.
  43.  * returns:  -1 -- error occured
  44.  *            ? -- the child process's exit status
  45.  ***/
  46. int shell(char *prompt)
  47. {
  48.    char *comspec = getenv("COMSPEC");
  49.  
  50.    if (!comspec) {
  51.       return -1;
  52.    }
  53.    if (putenv(prompt)) {
  54.       return -1;
  55.    }
  56.    return spawnl(P_WAIT, comspec, NULL);
  57. }
  58.  
  59. Lee Hollingworth
  60. s1110238@giaeb.cc.monash.edu.au
  61.