[英]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.