I am trying to redirect the output of my command line program when it is called with Process.Start()
. I've tried all permutations of RedirectStandardOutput
, UseShellExecute
and CreateNowWindow
and had no luck.
I know there are other ways of accomplishing this such as reading StandardOutput
after this but I would prefer to redirect it with arguments if possible into a file. I only care about the return code and only need the output of myprog.exe to go to a file. My program doesn't need to know what the output is.
var p = new Process();
p.StartInfo.FileName = @"myprog.exe";
p.StartInfo.Arguments = " " + InputFilename + " > " + OutputFilename;
p.StartInfo.RedirectStandardOutput = false;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();
var result = p.ExitCode;