简体   繁体   English

使用Shell执行重定向标准输出

[英]Redirect Standard Output with Shell Execute

I understand how to redirect StandardIO streams from Process objects in C# in general. 我理解如何从C#中的Process对象重定向StandardIO流。 However, I have to use ShellExecute for a particular command to work. 但是,我必须使用ShellExecute来执行特定命令。

Consequently, I am unable to redirect these streams which I need for logging purposes. 因此,我无法重定向这些我需要用于记录目的的流。

I've tried redirecting it like this: 我试过像这样重定向它:

procStart.FileName = m1g;
procStart.Arguments = ">> output.txt";

At which point I plan on just reading the text file back, but this doesn't seem to work. 此时我计划只读回文本文件,但这似乎不起作用。

Is it possible to do something like this? 可以这样做吗?

Pipe commands are implemented by cmd.exe . 管道命令由cmd.exe实现。 So you need to run cmd /c and add your executable path as argument 因此,您需要运行cmd /c并将可执行路径添加为参数

Process.Start("cmd.exe", "/c " + yourexecutablecommandline + " >> output.txt" ); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM