【问题标题】:process.StandardOutput.ReadToEnd() does not get the total StandardOutputprocess.StandardOutput.ReadToEnd() 没有得到总的 StandardOutput
【发布时间】:2018-04-12 00:27:44
【问题描述】:

我有一个 C# 应用程序,它访问命令行工具“cppcheck”,然后应该将此命令行工具的输出保存到变量“输出”中。

代码如下:

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 的总输出:

但是只有这段文本的上半部分被保存到变量“输出”中,即这部分:

如何捕获 cppcheck 的全部输出?

【问题讨论】:

    标签: c# visual-studio cppcheck


    【解决方案1】:

    你也应该联系Process.StandardError

    string error = p.StandardError.ReadToEnd();
    

    【讨论】:

    • 非常感谢您的回答。但是警告呢?它们是否也包含在“p.StandardError.ReadToEnd();”中?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-13
    • 1970-01-01
    相关资源
    最近更新 更多