【发布时间】:2014-05-03 12:22:38
【问题描述】:
我正在运行一个程序,该程序运行 driverquery.exe 命令并取回输出
pProcess.StartInfo.CreateNoWindow = true;
debugLog.WriteToLog("");
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
debugLog.WriteToLog("before start method");
pProcess.Start();
debugLog.WriteToLog("after start method");
if (windowTitleToHide.Length > 0)
{
WindowsUtil.HideWindow(windowTitleToHide);
}
if (null != attributeName && !"".Equals(attributeName))
Console.WriteLine(attributeName + " : ");
debugLog.WriteToLog("before read to end");
StreamReader reader = pProcess.StandardOutput;
String strOutput = string.Empty;
while (reader.Peek() > -1)
strOutput += reader.ReadLine();
debugLog.WriteToLog("after read to end");
Console.WriteLine(strOutput);
debugLog.WriteToLog("before wait for exit");
pProcess.WaitForExit();
debugLog.WriteToLog("after wait for exit");
pProcess.Close();
该过程大约需要 30 分钟才能完成。如果我通过 cmd 运行相同的进程,它总是在 2 分钟内完成。我曾尝试使用 readtoend 而不是 readline 但这也没有帮助。有人能说出这里出了什么问题吗?在我的日志中,我可以看到最后一行打印为 before wait for exit
PS:当我看到任务管理器中的进程时,driverquery.exe 正在运行但不消耗任何 CPU 周期。调用此代码的进程消耗了大约 99% 的 CPU。我确定调用代码在运行此代码时没有执行任何其他任务。
【问题讨论】:
-
查看是否向 StandardError 抛出错误。您可以从重新启用窗口开始,而不是重定向 StandardOutput 以查看它是否正在等待输入或为您提供一些其他诊断信息。
-
您是否将一些参数传递给 driverquery.exe?
-
不,我没有将任何参数传递给 driverquery。
-
请不要在问题标题中包含有关所用语言的信息,除非没有它就没有意义。标记用于此目的。