Solved

Parent Process Interaction with child process

Posted on 1998-11-12
5
289 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
ID: 1804913
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
ID: 1804914
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
ID: 1804915
i want in mfc ie..vc++1.5 in win3.11
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1804916
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
ID: 1804917
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

Too many email signature changes to deal with?

Are you constantly being asked to update your organization's email signatures? Do they take up too much of your time? Wouldn't you love to be able to manage all signatures from one central location, easily design them and deploy them quickly to users. Well, you can!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

863 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

24 Experts available now in Live!

Get 1:1 Help Now