创建一个进程并重定向其输入/输出,而不继承套接字句柄 [英] create a process and redirect its input/output and dont inherit socket handles
问题描述
是否可以创建一个进程并重定向其输入和输出,但将子进程设置为不继承套接字句柄? (可能是用CreateProcess pinvoke)
如果我使用UseShellExecute = true,孩子不继承套接字,但我不能重定向输出。
Is it possible to create a process and redirect its input and output but set the child not to inherit socket handles ? ( maybe pinvoke with CreateProcess somehow ) If I use UseShellExecute = true the child doesn't inherit the socket but I cant redirect output.
推荐答案
CreateProcess 需要 STARTUPINFO 作为其参数之一。此结构中的三个字段是in,out和错误句柄。
CreateProcess takes a STARTUPINFO as one of its parameters. Three of the fields in this struct are the in, out and error handles.
不要忘记设置 STARTF_USESTDHANDLES
flag。
Don't forget to set the STARTF_USESTDHANDLES
flag.
编辑:所以你必须设置 bInheritHandles
参数。有关继承句柄的详细信息,请参见此页面。
So you have to set the bInheritHandles
parameter. See this page for more information about inherited handles.
这篇关于创建一个进程并重定向其输入/输出,而不继承套接字句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!