StandardOutput.ReadToEnd 无限期挂起

StandardOutput.ReadToEnd Hangs Indefinitely

首先,我尝试了多种解决方案,包括此处列出的解决方案。 ProcessStartInfo hanging on "WaitForExit"? Why?StandardOutput.ReadToEnd() hangs

None 个正在为我工​​作,但都超时或挂起。您是否在我的代码中看到任何明显的错误?基本上,我正在尝试通过 C# 运行 一个 shell 脚本。当您手动 运行 时,脚本 运行 很好,但需要一段时间。 (大约一分钟)在我的代码中,它在 ReadToEnd 上挂起。这是代码...

        public psResult RunScript(string scriptToExecute, string scriptArgument)
    {
        var logEnabled = true;

        scriptToExecute = ConfigurationManager.AppSettings["s-path"] + scriptToExecute;

        if (!System.IO.File.Exists(scriptToExecute))
            return new psResult
            { HasErrors = true, ErrorMessage = $"{scriptToExecute} is not found!" };

        var process = new Process
        {
            StartInfo =
            {
                UseShellExecute = false,
                RedirectStandardOutput = true,
                FileName = ConfigurationManager.AppSettings["exe"],
                Arguments = $"{scriptToExecute} {scriptArgument}"
            }
        };

        string logCapture = "";

        try
        {
            process.Start();

            logCapture = process.StandardOutput.ReadToEnd();

            process.WaitForExit();
        }
        catch (Exception e)
        {
            return new psResult
            { HasErrors = true, ErrorMessage = $"{e.InnerException}", RawResult = logCapture };
        }

        return new psResult
        { HasErrors = false, ErrorMessage = $"{scriptToExecute}.", RawResult = logCapture };
    }

原来是我机器的脚本权限问题。一旦我将其更改为 ByPass,它就起作用了。所以,这不是密码!