gpt4 book ai didi

c# - StandardOutput.ReadToEnd() 挂起

转载 作者:IT王子 更新时间:2023-10-29 03:53:11 24 4
gpt4 key购买 nike

<分区>

我有一个经常使用外部程序并读取其输出的程序。使用您通常的进程重定向输出,它工作得很好,但是当我尝试读取它时,一个特定的参数由于某种原因挂起,没有错误消息 - 无一异常(exception),它只是在到达该行时“停止”。我当然使用一个集中函数来调用和读取程序的输出,它是这样的:

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 > 1)
{
output += result;
}
if (error.Length > 1)
{
output += error;
}
Return output;
}
catch (Exception objException)
{
throw objException;
}
}

挂起的行是 result = proc.StandardOutput.ReadToEnd();,但同样,并非每次都挂起,仅在发送特定参数(“start-server”)时挂起。所有其他参数都工作得很好——它读取值并返回它。它的悬挂方式也很奇怪。它不会卡住或给出错误或任何东西,它只是停止处理。就好像它是一个“返回”命令,除了它甚至不返回调用函数,它只是在接口(interface)仍然启动和运行的情况下停止一切。以前有人经历过吗?任何人都知道我应该尝试什么?我假设它在流本身中是意想不到的,但是有什么方法可以处理/忽略它以便它读取它吗?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com