home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.msdos.programmer
- Path: sparky!uunet!munnari.oz.au!bruce.cs.monash.edu.au!monu6!giaeb!s1110238
- From: s1110238@giaeb.cc.monash.edu.au (Lee Hollingworth)
- Subject: Re: question on spawning DOS from C prog
- Message-ID: <s1110238.726575527@giaeb>
- Sender: news@monu6.cc.monash.edu.au (Usenet system)
- Organization: Monash University, Melb., Australia.
- References: <1993Jan7.140524.15787@ns1.cc.lehigh.edu>
- Date: Sat, 9 Jan 1993 10:32:07 GMT
- Lines: 49
-
- jmt7@ns1.cc.lehigh.edu (JOHN M. TROIANO) writes:
-
- >In article <tim.36.726368023@tim.src.utah.edu>, tim@tim.src.utah.edu (Tim Ma) wr
- >ites:
-
- >Hi, I am the original poster of this problem: this is especially to
- >Tim and Wolfgang. I tried the code below (which is I think what both
- >of you guys are suggesting) but it does'nt work (the new prompt
- >string is ignored). Any ideas? - John.
-
- I am neither Tim nor Wolfgang, but the following *does* work!
-
- #include <process.h>
- #include <stdlib.h>
- #include <stdio.h>
-
- int shell(char *);
-
- void main(void)
- {
- static char *message = "PROMPT=Type EXIT to return to program $_$P$G ";
-
- if (shell(message) == -1) {
- fprintf(stderr, "Error: cannot shell to DOS\n");
- }
- }
-
- /***
- * function: shell
- * purpose: shell out to DOS operating system.
- * passed: prompt -- prompt to be displayed in DOS environment.
- * returns: -1 -- error occured
- * ? -- the child process's exit status
- ***/
- int shell(char *prompt)
- {
- char *comspec = getenv("COMSPEC");
-
- if (!comspec) {
- return -1;
- }
- if (putenv(prompt)) {
- return -1;
- }
- return spawnl(P_WAIT, comspec, NULL);
- }
-
- Lee Hollingworth
- s1110238@giaeb.cc.monash.edu.au
-