Reputation: 22255
I can run a console process using the following C# code. The goal is also to collect all the output from such process:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.Arguments = commandLine;
proc.StartInfo.FileName = "signtool.exe";
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.Start();
if (proc.WaitForExit(10000))
{
Debug.WriteLine(proc.StandardOutput.ReadToEnd());
}
What I receive is this:
"Done Adding Additional Store\r\n"
But when I do the same from a Windows command line I get this:
Done Adding Additional Store
SignTool Error: File not found: C:\SomeBadFile.exe
Why am I getting only the first line of output with my code?
Upvotes: 1
Views: 283
Reputation: 5672
Have you tried redirecting and watching StandardError too? It seem likley that this is output to the error stream.
Upvotes: 1
Reputation: 166336
Seeing as the line you are missing seems like an error message, should you not be looking at Process.StandardError Property
When a Process writes text to its standard error stream, that text is normally displayed on the console. By redirecting the StandardError stream, you can manipulate or suppress the error output of a process. For example, you can filter the text, format it differently, or write the output to both the console and a designated log file.
Upvotes: 2