Win9x and NT 4.0
Borland C++ Builder 3.0
Application is 32-bit
I'm trying to spawn another program and wait until it is done. I am using
spawnl and cwait, but I can't seem to get it to work correctly.
When using:
spawnl (P_WAIT, "Adobe\\Setup.exe", "Adobe\\Setup.exe", NULL);
a second instance of the current (parent) process, NOT "Adobe\\Setup.exe" is
spawned; both are hung.
When using:
int childid = spawnl (P_NOWAIT, "subdir\\runme.exe", "subdir\\runme.exe",
NULL);
cwait(0, childid, WAIT_CHILD);
childid is a negative number (is that normal?), and cwait and the child
process hangs until I kill the parent process, at which point the child
process continues execution normally.
If I show a Message box:
int childid = spawnl (P_NOWAIT, "subdir\\runme.exe", "subdir\\runme.exe",
NULL);
ShowMessage(childid);
int r = cwait(0, childid, WAIT_CHILD);
cwait returns the childid (r==childid) IMMEDIATELY, though
"subdir\\runme.exe" continues to run in the background.
Am I using these funcs in just completely the wrong way or what? Is there
an alternative?
Thanks.
Chris B.
---------------------
Chris Bordeman
Software Developer
EMI
PROCESS_INFORMATION pi = { 0 };
CreateProcess(..., &pi);
WaitForSingleObject(pi.hProcess, INFINITE);
--
Bret Pehrson
R&D Manager
Steton Technology Group
peh...@nospam.steton.com
Remove nospam to send e-mail
*When replying via e-mail, please carbon newsgroup*
NOSPAM
_PROCESS_INFORMATION pi = {0};
STARTUPINFO si = {0};
int created = CreateProcess(
fullpath, // pointer to name of executable module
NULL, // pointer to command line string
NULL, // pointer to process security attributes
NULL, // pointer to thread security attributes
FALSE, // handle inheritance flag
0, // creation flags
0, // pointer to new environment block
startupdir, // pointer to current directory name
&si, // pointer to STARTUPINFO
&pi // pointer to PROCESS_INFORMATION
);
if (!created)
{
blah blah blah...
}
WaitForSingleObject(
pi.hProcess, // handle of object to wait for
INFINITE // time-out interval in milliseconds
);
and the app just hangs on the WaitForSingleObject, same behavior as before -
I kill the app or remove the WaitForSingleObject and the child process runs
fine.
I have no idea what is going on.
(win98 SE)
"Bret Pehrson" <peh...@nospam.steton.com> wrote in message
news:38B47B33...@nospam.steton.com...
I think you don't have initialized STARTUPINFO correctly:
[...]
STARTUPINFO start;
[...]
memset (&start, 0, sizeof(start));
start.cb = sizeof (STARTUPINFO);
[...]
>and the app just hangs on the WaitForSingleObject, same behavior as before -
>I kill the app or remove the WaitForSingleObject and the child process runs
>fine.
If this is a Windows program then you can not just stop and wait for the
appliction unless the waiting code is in a thread. If the code is part of the
main windows application then you have to keep the message system
running.
This means you need code that looks something like this (pseudo
code only):
while (task is running running) {
if (PeekMessage()) {
GetMessage();
DispatchMessage();
}
Sleep(100);
}
This is a message pump. If you search deja.com you are bound to find
lots of proper examples of how to code these.
Jussi Jumppanen
Author of: Zeus for Windows, Win32 (Brief, WordStar, Emacs) Text Editor
"The C/C++, Java, HTML, Pascal, Cobol, Fortran programmer's text editor"
http://www.zeusedit.com
Here is my code in it's current incarnation:
int created = CreateProcess(
fullpath, // pointer to name of executable module
NULL, // pointer to command line string, NULL == same
NULL, // pointer to process security attributes
NULL, // pointer to thread security attributes
FALSE, // handle inheritance flag
0, // creation flags
0, // pointer to new environment block
curdir, // pointer to current directory name
&si, // pointer to STARTUPINFO
&pi // pointer to PROCESS_INFORMATION
);
[...]
while (true)
{
int result;
result = WaitForSingleObject(pi.hProcess, 1);
if (result == WAIT_FAILED || result == WAIT_OBJECT_0)
break;
Application->ProcessMessages();
}
Thanks,
Chris B.
This is bad. You are polling. Use MsgWaitForMultipleObjects().
Andy
>
> Thanks,
> Chris B.
>
Andy