如何使用win32的CreateProcess函数等待子进程完成写入文件 [英] How to use win32 CreateProcess function to wait until the child done to write to file

查看:473
本文介绍了如何使用win32的CreateProcess函数等待子进程完成写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
im not 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

推荐答案

稍微修改Benoits的答案。您可以在父进程中创建一个事件,并使用 WaitForSingleObject 来等待该事件。然后,孩子可以通过调用 SetEvent 来发出此事件。

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

重要的是子进程将继承所有可继承的句柄,因此CreateProcess必须将第五个参数设置为true(bInheritHandles)。

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.

这篇关于如何使用win32的CreateProcess函数等待子进程完成写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆