Solved

Parent Process Interaction with child process

Posted on 1998-11-12
5
286 Views
Last Modified: 2013-12-29
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).
0
Comment
Question by:gspk
  • 2
  • 2
5 Comments
 

Author Comment

by:gspk
Comment Utility
Actually i have called format.com 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.
ex:-
UINTi; i=WinExec("vsres.exe",SW_SHOWMAXIMIZED);
if(vsres.exe has completed)// i.e formatting of floppy completed
    copy files to floppy disk;

0
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
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:

ON ERROR GOTO ISDONE
Retry:
X = FILELEN( semaphore )
DoEvents
GOTO RETRY
' =========
ISDONE:
RESUME ISDONE1
'
ISDONE1:
.
This is ugly but does work.

M
0
 

Author Comment

by:gspk
Comment Utility
i want in mfc ie..vc++1.5 in win3.11
0
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
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!

M

0
 
LVL 27

Accepted Solution

by:
BigRat earned 100 total points
Comment Utility
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!
0

Featured Post

Why spend so long doing email signature updates?

Do you spend loads of your time carrying out email signature updates? Not very interesting are they? Don’t let signature updates get you down. Let Exclaimer Cloud - Signatures for Office 365 make managing email signatures a breeze.

Join & Write a Comment

If you Lost your Administrator password for Windows XP, Vista, or 7 this CD will help you reset the password to blank so you can log in. Once in you should change that blank password to something!! Download the ISO on this page http://www.spl…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now