Generally you do not want to "wait" for a program to complete; what you want to do is run
the program and do something when it completes. See my essay on asynchronous process
notification on my MVP Tips site.
If you just "wait", then your program appears to lock up; the GUI is non-responsive. This
is usually considered tasteless.
The normal way of spawning a program is to use CreateProcess or ShellExecuteEx and get the
process handle. You then set some state that indicates that the process is running, and in
my model, spawn a thread that blocks on the handle. The menu item that would launch the
process is then disabled, e.g.,
void CWhatever::OnUpdateLaunchProcess(CCmdUI * pCmdUI)
So you set ProcessIsRunning to TRUE when the you have successfully launched the process.
In my model, when the thread comes out of its wait, it does a PostMessage to the main GUI
thread. In the message handler for this user-defined message will set the ProcessIsRunning
flag to FALSE so you can launch another process. If you want to capture the output from
the process, you might want to look at my process class as well, which uses a pipe to
retrieve the stdout/stderr output (you can do whatever you want with it; in my case, I
added it to a ListBox so the user could see the compiler messages).
Joseph M. Newcomer [MVP]
MVP Tips: http://www.yqcomputer.com/