Synchronization Issue

Hello All,

I am new to this concept so please help. The issue is below

I am executing one batch file using WinExc function in MFC. This is done using the BeginThread concept. But now problem is the thread is getting over before the .exe finished the execution. SO my requirement is we have to wait until the exe running is over. The .exe will take nearly 30 to 40 sec to finish his task. I cant use the sleep function to give detaly beacuse after this execution of exe i have to display the data to text file and because of sleep function it is taking more time or at the end of my program only it is updating txt file.
So it will be better if any one suggest how to handle this condition.

Thanks and Regards,
Swapnil Jarali
I am executing one batch file using WinExc function in MFC.
Using WinExc? Can you more precise.

This is done using the BeginThread concept.
I'm not sure why you'd need a thread because now you have two concurrent activities to wait for.

But now problem is the thread is getting over before the .exe finished the execution.
The thread has to wait for the process to complete and something has to eventually wait for the thread to complete and clean up behind it.

So it will be better if any one suggest how to handle this condition.
Suggestions have been stated, but you need to be more specific (describe actual functions you're using or post the relevant code) to get more specific help.
Hello
The condition is as below
I have to execute one .bat file which will internally executes the .exe file and results will br stored in one .txt file. Now the next task is i have to print the .txt file data to GUI(text box).
The .exe mentioned above will do some task which will take nearly 40 sec.
So the code is
WinExec(batFilePath, SW_HIDE);
sleep(60000);
Considering that the code will take 60000 msec to finish the task.

Now my issue is i have to repeat the .exe execution in different .bat file with different input. and display the results after each iteration to GUI.

To Solve the above problem i created the Threads but it is not working for me.

Thanks and Regards,
Swapnil
WinExec http://msdn.microsoft.com/en-us/library/windows/desktop/ms687393%28v=vs.85%29.aspx
Note This function is provided only for compatibility with 16-bit Windows. Applications should use the CreateProcess function

You should be using CreateProcess. It returns a handle that you can use with WaitForSingleObject. which allows you to wait for the process to complete.

You execute a batch file by running cmd.exe /c <batch file name>
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true

You don't need a thread, but if you want to use one, you'll need to describe what calls you've used in detail.
Topic archived. No new replies allowed.