将CMD.exe输出重定向到管道 [英] Redirect CMD.exe output to a pipe
问题描述
我可以使用CreateProcess
(或ShellExecute
或任何其他调用cmd.exe
的方法来运行批处理脚本)并将所有输出重定向到我的进程所拥有的管道吗?如何为子cmd.exe进程提供到管道端点之一的句柄?甚至可以通过这种方式使用管道吗?
Can I use CreateProcess
(or ShellExecute
, or any other means of invoking cmd.exe
to run a batch script) and have all output redirected to a pipe owned by my process? How do I give the child cmd.exe process a handle to one of the pipe endpoints? Is it even possible to use a pipe in this way?
(搜索"cmd.exe"和"pipes"这两个术语的变体只不过是使用|(pipe)字符将输出重定向到另一个程序)
(Googling for variations on the terms "cmd.exe" and "pipes" is nothing but redirecting output to another program using the |(pipe) character)
推荐答案
Here's how you would do it with .NET: http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput.aspx
对于C/C ++: http://msdn.microsoft.com/zh-CN/library/ms682499(v=VS.85).aspx
这篇关于将CMD.exe输出重定向到管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!