Mail Archives: djgpp/1999/04/28/07:31:28
From: | Maxximo <mssmsoft AT my-dejanews DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: I have a question, and need some help...
|
Date: | Wed, 28 Apr 1999 07:54:01 GMT
|
Organization: | Deja News - The Leader in Internet Discussion
|
Lines: | 62
|
Message-ID: | <7g6eqo$i6s$1@nnrp1.dejanews.com>
|
References: | <7g54u0$r65 AT newsops DOT execpc DOT com>
|
NNTP-Posting-Host: | 138.132.53.11
|
X-Article-Creation-Date: | Wed Apr 28 07:54:01 1999 GMT
|
X-Http-User-Agent: | Mozilla/3.04Gold (X11; I; OSF1 V4.0 alpha)
|
X-Http-Proxy: | 1.0 x9.dejanews.com:80 (Squid/1.1.22) for client 138.132.53.11
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
In article <7g54u0$r65 AT newsops DOT execpc DOT com>,
"Joshua Tacey" <josht AT softhouse DOT com> wrote:
> Hi everyone, I am sorta new to C, I have read a few books, but none of them
> cover in any debth. Executing other programs and such. So i have this
> question.
>
> In an install routine of a game that I am working on,
>
> I need for the User to type in a path for the files to go into and then have
> that path be passed as an argument to the program that the install program
> must execute. I need for the Origional Program (The Install One) to keep on
> running after the program it exec's is complete.
Your problem have two solution.
In standard C, you must:
-create a new process (son) with fork()
-in the son code, call the exec..() function
-in the parent code, call the wait() function
like this:
pid_t pid;
int status;
pid = fork();
if (pid == 0) { /* son code */
execl("/this/is/new/program.exe", "program.exe", "argument", 0);
exit(1); /* only if exec fails */
}
/* parent code */
if (pid < 0) {
perror("fork");
}
else {
wait(&status);
/* see wait() manual page to know more about status */
}
Under Djgpp, I think that you must use spawn() with the flag P_WAIT to
execute a son process and wait for its end. See the spawn() manual page for
more info.
I hope this help you.
Ciao
Maxximo
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
- Raw text -