G
Guest
Hello,
I have a C# application in which I start another process which produces
output to stdout and stderr. In fact, that process is the uSoft VS2005 C/C++
compiler itself! I would like to capture the results of the compile and
display them in a RichTextBox. The problem I'm having is that when I
intentionally introduce an error in the C code I'm compiling, I can't read
the error output in my C# program. I've tried redirecting both stdout and
stderr (not at the same time) but I can never capture the error messages,
only the start of the compile itself. If I simply open a command window and
manually do th compile from there, I see the error messages fine. Below is
an example of a simplified version of the C# code I'm using. This code uses
stderr but I've also tried it for stdout (the C/C++ compiler actually appears
to output its code syntax error messages to stdout rather than stderr):
Process compile = new Process();
compile.StartInfo.FileName = "cl.exe";
compile.StartInfo.Arguments = "main.c";
compile.StartInfo.CreateNoWindow = true;
richTextBox_LogDisplay.AppendText(
compile.StartInfo.FileName + " " +
compilerArguments + "\n");
// Set UseShellExecute to false for redirection.
compile.StartInfo.UseShellExecute = false;
// Redirect the standard output of the compile command.
compile.StartInfo.RedirectStandardError = true;
compile.Start();
// Synchronously read the standard output of the spawned process.
string output = compile.StandardError.ReadToEnd();
if (output != null)
{
richTextBox_LogDisplay.AppendText(output);
richTextBox_LogDisplay.AppendText("\n");
}
compile.WaitForExit();
I have a C# application in which I start another process which produces
output to stdout and stderr. In fact, that process is the uSoft VS2005 C/C++
compiler itself! I would like to capture the results of the compile and
display them in a RichTextBox. The problem I'm having is that when I
intentionally introduce an error in the C code I'm compiling, I can't read
the error output in my C# program. I've tried redirecting both stdout and
stderr (not at the same time) but I can never capture the error messages,
only the start of the compile itself. If I simply open a command window and
manually do th compile from there, I see the error messages fine. Below is
an example of a simplified version of the C# code I'm using. This code uses
stderr but I've also tried it for stdout (the C/C++ compiler actually appears
to output its code syntax error messages to stdout rather than stderr):
Process compile = new Process();
compile.StartInfo.FileName = "cl.exe";
compile.StartInfo.Arguments = "main.c";
compile.StartInfo.CreateNoWindow = true;
richTextBox_LogDisplay.AppendText(
compile.StartInfo.FileName + " " +
compilerArguments + "\n");
// Set UseShellExecute to false for redirection.
compile.StartInfo.UseShellExecute = false;
// Redirect the standard output of the compile command.
compile.StartInfo.RedirectStandardError = true;
compile.Start();
// Synchronously read the standard output of the spawned process.
string output = compile.StandardError.ReadToEnd();
if (output != null)
{
richTextBox_LogDisplay.AppendText(output);
richTextBox_LogDisplay.AppendText("\n");
}
compile.WaitForExit();