Parent Process Interaction with child process

Iam using Winexec API to execute a dos exe for formatting disk  and when i call this function that dos exe is running in a separate process(child) and parent is going to execute next stmt. but only when that child process(i.e formatting) has completed then only parent should go to next stmt. execution how to know whether child has completed execution so that i can go to next stmt.? I have seen Spawn and exec functions to run dos exe but they are not supported in Win3.11 Please help me? I want in Windows(16bit).
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

BigRatConnect With a Mentor Commented:
The reason why WinExec returns as soon as the program has been launched is that under 16-bit Windows you must always be ready to release control so that another process can run. Although in this particular case the program is a DOS program and the process switching takes place at the DOS level, Windows must first create and maintain the DOS box in which the process it to run.
   A consequence of this is that sitting in a loop waiting for some file to pop up is also not the best user friendly way to do this. The correct way is for a notification to occur when the DOS program has finished. Mark2150 suggests that you create a file of a well known name in a well known place or location and loop wait for it to appear. This is about the best technique which is available to you, except that I would create a timer object and test for the existance of the file when the timer message occurs. Here I can count the number of (say 1 second messages) and if it exceeds some fixed value (10 mins) ask the user via a messagebox whether things are still ok. You must delete the file before launching the program and after it appears.
    You should reject this answer with a comment asking Mark2150 to pick up the points.
   have ratitude!
gspkAuthor Commented:
Actually i have called inside a turbo c program for formatting a disk. In a particular dialog when user clicks a button
labeled format then i call this turbo exe file so it goes to dos mode from windows until it formats the disk and i want to take next action in the program only when entire formatting is completein that turbo c exe but the problem is as soon as i call this exe with winexec it is running separately and the program is going to next stmt. but i want next stmt. to be executed based on that turbo c programs  outputi.e whether floppy formatted or not? Problem is that it is running separartely,but  i want to stop parent program from going to next stmt. until formatting is completed in that called dos exe i.e it has to complete execution. because next stmt. is based on that dos exe output.
UINTi; i=WinExec("vsres.exe",SW_SHOWMAXIMIZED);
if(vsres.exe has completed)// i.e formatting of floppy completed
    copy files to floppy disk;

Only way to work around this one that I know of is to spawn a batch file that deletes a semaphore file when it finishes it's run.

Say you code creates the file immediately prior to firing the task, then the batch file deletes the file after the FORMAT task is complete. In this way your parent can watch for the semaphore file to disappear. I use FILELEN() to give an error when the file disappers In VB you code something like:

X = FILELEN( semaphore )
' =========
This is ugly but does work.

gspkAuthor Commented:
i want in mfc in win3.11
Technique shown will work on any version of OS. Converting *five* lines to c++ shouldn't be hard - of those five lines two are error trap!


All Courses

From novice to tech pro — start learning today.