如何使用win32 CreateProcess函数等待子进程完成写入文件
你好 我不是 win32 程序员,这对我来说是全新的。 我喜欢从我的父 win32 应用程序打开进程(好吧,这是我知道该怎么做) 然后子进程写入文本文件并自行关闭。我如何在父应用程序中检测到子应用程序已完成写入文本文件。然后从父应用程序读取文本文件。这都是 win32 c++ 中的 谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对伯努瓦的答案稍作修改。您可以在父进程中创建一个事件并使用 WaitForSingleObject 等待该事件。然后子级可以通过调用 SetEvent 来发出此事件的信号。
http://msdn.microsoft.com/en -us/library/ms686211%28v=vs.85%29.aspx
重要的是子进程将继承所有可继承的句柄,因此 CreateProcess 必须将第五个参数设置为 true (bInheritHandles)。
这样子进程就不必退出来检查文件是否已写入。
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.
PROCESS_INFORMATION
结构(这是 CreateProcess 的最后一个参数)包含成员hProcess
。这是新进程的句柄,您可以使用WaitForSingleObject
等待它。The
PROCESS_INFORMATION
structure (which is the last argument to CreateProcess) contains memberhProcess
. This is a handle to the new process, which you can wait on usingWaitForSingleObject
.如果您的孩子将在文件创建后退出,您可以使用
::WaitForSingleObject
使用::CreateProcess
返回的进程句柄。If your child will exit after file creation you can use
::WaitForSingleObject
using the process handle returned by::CreateProcess
.