process.StandardOutput.ReadToEnd() 没有得到总的 StandardOutput
process.StandardOutput.ReadToEnd() does not get the total StandardOutput
我有一个 C# 应用程序,它访问命令行工具 "cppcheck",然后应该将此命令行工具的输出保存到变量 "output".
代码如下:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C cppcheck" + " \"" + currentEvent.currentEventFilePath + "\"";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true;
process.StartInfo = startInfo;
process.Start();
//the following line is the problem. Output of cppcheck is not completely read:
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
问题是 ReadToEnd() 函数实际上并没有读到最后...而是在我需要的重要部分之前停止。
这里是 cppcheck 的总输出:
但是只有这段文字的上半部分被保存到变量"output"中,即这部分:
如何捕获 cppcheck 的全部输出?
你也应该挂钩 Process.StandardError
string error = p.StandardError.ReadToEnd();
我有一个 C# 应用程序,它访问命令行工具 "cppcheck",然后应该将此命令行工具的输出保存到变量 "output".
代码如下:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C cppcheck" + " \"" + currentEvent.currentEventFilePath + "\"";
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true;
process.StartInfo = startInfo;
process.Start();
//the following line is the problem. Output of cppcheck is not completely read:
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
问题是 ReadToEnd() 函数实际上并没有读到最后...而是在我需要的重要部分之前停止。
这里是 cppcheck 的总输出:
但是只有这段文字的上半部分被保存到变量"output"中,即这部分:
如何捕获 cppcheck 的全部输出?
你也应该挂钩 Process.StandardError
string error = p.StandardError.ReadToEnd();