I am trying to run a command in cmd.exe, and redirect the output to a textfile. I have verified that the command is being executed, but when I call StandardOutput.ReadToEnd() or StandardError.ReadToEnd(), an empty string is returned instead of the text output from the command. Am I missing something?
ProcessStartInfo PSI = new ProcessStartInfo("cmd.exe", command);
PSI.UseShellExecute = false;
PSI.CreateNoWindow = true;
PSI.RedirectStandardInput = true;
PSI.RedirectStandardOutput = true;
PSI.RedirectStandardError = true;
PSI.Arguments = "/c";
var proc = Process.Start(PSI);
proc.WaitForExit();
string output = proc.StandardOutput.ReadToEnd();
Console.WriteLine(output);
string errors = proc.StandardError.ReadToEnd();
Console.WriteLine(errors);