[英]Getting GCC's output from command line when running it through C#
我目前正在通过C#应用程序编译C程序。 如果gcc输出任何内容,则表示存在错误。 我想检索此错误并将其显示给用户。
目前,我正在这样做...
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = _cCompilerPath,
Arguments = " ./file.c",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
proc.Start();
string message = string.Empty;
while (!proc.StandardOutput.EndOfStream)
{
string line = proc.StandardOutput.ReadLine();
message = string.Concat(message, line);
}
MessageBox.Show("OUTPUT :" + message);
但是,即使程序中出现错误,也不会将任何内容重定向到标准输出,并且EndOfStream始终返回true。
我敢打赌,它是写给StandardError
。
RedirectStandardError = true,
....
while (!proc.StandardError.EndOfStream)
{
string line = proc.StandardError.ReadLine();
message = string.Concat(message, line);
}
使用Console.WriteLine("message");
如果您正在使用控制台。 MessageBox
用于WinForms应用程序。
Console.WriteLine("OUTPUT: {0}", message);
Console.WriteLine
写入标准输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.