ScottishTapWater
ScottishTapWater

Reputation: 4806

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?

Upvotes: 1

Views: 1568

Answers (1)

Perfect28
Perfect28

Reputation: 11317

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" ); 

Upvotes: 3

Related Questions