我有一个经常使用外部程序并读取其输出的程序.它使用你通常的进程重定向输出很好地工作,但是当我尝试读取它时,由于某种原因,一个特定的参数会挂起,没有错误消息 - 没有例外,当它到达该行时它只是'停止'.我当然使用集中式函数来调用和读取程序的输出,这是:
public string ADBShell(string adbInput)
{
try
{
//Create Empty values
string result = string.Empty;
string error = string.Empty;
string output = string.Empty;
System.Diagnostics.ProcessStartInfo procStartInfo
= new System.Diagnostics.ProcessStartInfo(toolPath + "adb.exe");
procStartInfo.Arguments = adbInput;
procStartInfo.RedirectStandardOutput = true;
procStartInfo.RedirectStandardError = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
procStartInfo.WorkingDirectory = toolPath;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
// Get the output into a string
proc.WaitForExit();
result = proc.StandardOutput.ReadToEnd();
error = proc.StandardError.ReadToEnd(); //Some ADB outputs use this
if (result.Length …Run Code Online (Sandbox Code Playgroud) 我正在运行构建,我希望能够在发生这种情况时查看进度.但是如果构建有错误,我还想保存输出.
我知道我可以使用Process.UseShellExecute = false,RedirectStandardOutput但是,这只是故事的一部分.
我怎样才能做到这一点?