Solved

Parent Process Interaction with child process

Posted on 1998-11-12
5
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

How to record audio from input sources to your PC – connected devices, connected preamp to record vinyl discs, streaming media, that play through your audio card: Vista, Windows 7, Windows 8, Windows 8.1 and Windows 10 – both 32 bit & 64.
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

726 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