windows 匿名管道:父进程与子进程通信

windows 匿名管道:父进程与子进程通信 ,第1张

windows 匿名管道: 父进程与子进程通信 (进程间通信之CreatePipe)

看了很多篇相关的资料,感觉这个还是比较靠谱的:

进程间通信之CreatePipe   https://blog.csdn.net/dacxu/article/details/30071081

特别是 SetHandleInformation() 非常的关键,我在写代码的过程中,才发现,没了这个,程序都无法运行了。


// Create a pipe for the child process's STDOUT.
if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0) )
ErrorExit(TEXT("StdoutRd CreatePipe"));

// Ensure the read handle to the pipe for STDOUT is not inherited.
if ( ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) )
ErrorExit(TEXT("Stdout SetHandleInformation"));

// Create a pipe for the child process's STDIN.
if (! CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0))
ErrorExit(TEXT("Stdin CreatePipe"));

// Ensure the write handle to the pipe for STDIN is not inherited.
if ( ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) )
ErrorExit(TEXT("Stdin SetHandleInformation"));

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/585607.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-12
下一篇 2022-04-12

发表评论

登录后才能评论

评论列表(0条)

保存