[英]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.