0

我一直在阅读如何从 C# ASP.NET 应用程序中执行 Win32 命令行程序,由于某种原因,下面的代码在执行期间永远不会完成,无限期地卡output = p.StandardOutput.ReadToEnd();网上。

该代码在从本地调试服务器执行时运行良好(在 Visual Studio 中按 F5),但是当通过浏览器通过完整 URL (myexample.com/testapp) 访问它时,调试器从未超出该output=...行。

    ProcessStartInfo info = new ProcessStartInfo(@"FetchIntranetPageSpecial.exe");
    info.Arguments = "hostname";
    info.UseShellExecute = false;
    info.RedirectStandardOutput = true;
    info.RedirectStandardError = true;
    info.RedirectStandardInput = true;
    info.CreateNoWindow = true;

    Process p = System.Diagnostics.Process.Start(info);
    p.Start();

    // Capture the output
    output = p.StandardOutput.ReadToEnd();  // debugger does not move past this line
    p.Close();

.exe 是一个简单的 http 请求应用程序,不访问本地文件或任何东西,将结果输出到控制台。

起初我认为这可能是一个权限问题,因此出于调试目的将FetchIntranetPageSpecial.exe权限设置为“所有人,一切” - 通过 localhost 访问时仍然可以正常工作,但在远程访问时仍然挂起。

关于下一步我可以尝试什么的任何指示?

编辑:我还阅读了此页面Program doesn't terminate when using processes,但在这种情况下,调试器在此行进入无限期“等待”状态:

while (read.Peek() >= 0)      // stuck on this line
    Console.WriteLine(read.ReadLine());
4

0 回答 0