开发者

Redirect CMD.exe output to a pipe

开发者 https://www.devze.com 2023-03-21 06:59 出处:网络
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 pr

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?

(Googling for variations on the terms "cmd.exe" and "pipes" is nothin开发者_开发问答g 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

And for C/C++: http://msdn.microsoft.com/en-us/library/ms682499(v=VS.85).aspx


Probably this will help... it is in VB.NET but it shouldn't be hard to change it to C#...

http://blogs.msdn.com/b/rahulso/archive/2006/04/01/run-a-command-from-the-command-prompt-and-get-its-output-in-a-windows-application.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号