简体   繁体   中英

Redirect Standard Output with Shell Execute

I understand how to redirect StandardIO streams from Process objects in C# in general. However, I have to use ShellExecute for a particular command to work.

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 . So you need to run cmd /c and add your executable path as argument

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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