我正在尝试使用重定向输入和输出创建子进程(如此处所述 –
http://msdn.microsoft.com/en-us/library/ms682499(VS.85).aspx).
For the people that don’t want to bother reading the source code on that page,the author is using anonymous pipes to redirect the child’s input and output. The parent process writes to the child process’s input and reads from the child process’s output.
然而,在该代码中,程序在读取和写入之后(在WriteToPipe和ReadFromPipe中)关闭管道,因此实际上程序只读取文件,将其转储到子进程输入流上,然后读取子进程响应.
现在,我正在寻找的代码是我们不会关闭管道的代码,但是我们会不断发布请求并读取子进程响应(与仅发出1个请求相反).
我已尝试对上面发布的链接上给出的源代码进行了几处修改,但无论我尝试什么,程序总是在ReadFromPipe()函数中调用ReadFile()时挂起(它可能等待孩子退出 – 但是正如我所说,我希望得到孩子的回应,然后向其发送其他请求).
关于我如何克服这一点的任何想法?
更新:
任何人至少可以告诉我,使用带有RedirectStandardInput和RedirectStandardOutput的.NET Process类是一个不错的选择吗?