How to use win32 CreateProcess function to wait while a child writes to a file

Hi im not a win32 programmer and all its new to me. I like to open the process from my parent win32 application (well, I know how to do this) the child process is then written to a text file and closes it. how can I detect in the parent application that the child application has written to a text file. and then from the parent application to read the text file. that's all in win32 c ++ thanks

+4
source share
3 answers

A slight modification to Benoit's answer. You can create an event in the parent process and wait for this event with WaitForSingleObject . This event can then be reported to the child by calling SetEvent .

http://msdn.microsoft.com/en-us/library/ms686211%28v=vs.85%29.aspx

It is important that the child process inherits all inherited descriptors, so the fifth parameter true (bInheritHandles) must be set for CreateProcess.

Therefore, the child process does not have to exit to verify that the file was written.

+4
source

The PROCESS_INFORMATION structure (which is the last argument to CreateProcess) contains the hProcess element. This is the handle to the new process that can be expected when using WaitForSingleObject .

+4
source

If your child exits after creating the file, you can use ::WaitForSingleObject using the process handle returned by ::CreateProcess .

0
source

All Articles