How to use win32 CreateProcess function to wait until the child done to write to file

扶醉桌前 提交于 2019-12-10 16:58:03

问题


Hello im not win32 programmer and its all new to me. i like to open process from my parent win32 application ( ok this is i know how to do) the child process then write to text file and close it self . how can i detect in the parent application that the child application done writing to the text file . and then from the parent app to read the text file . this is all in win32 c++ Thanks


回答1:


A slight modification of Benoits answer. You can create an event in the parent process and wait for that event with WaitForSingleObject. This event can then be signaled by the child through a call to SetEvent.

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

It's important that the child process will inherit all inheritable handles, so CreateProcess has to have the fifth parameter set to true (bInheritHandles).

This way the child process doesn't have to exit for you to check that the file has been written.




回答2:


The PROCESS_INFORMATION structure (which is the last argument to CreateProcess) contains member hProcess. This is a handle to the new process, which you can wait on using WaitForSingleObject.




回答3:


If your child will exit after file creation you can use ::WaitForSingleObject using the process handle returned by ::CreateProcess.



来源:https://stackoverflow.com/questions/5907917/how-to-use-win32-createprocess-function-to-wait-until-the-child-done-to-write-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!