从C#/ASP.NET中运行的命令行程序永远不会完成
我一直在阅读如何在C#ASP.NET应用程序中执行Win32命令行程序,由于某种原因,下面的代码在执行过程中永远不会完成,会无限期地卡在从C#/ASP.NET中运行的命令行程序永远不会完成,c#,asp.net,process,system.diagnostics,processstartinfo,C#,Asp.net,Process,System.diagnostics,Processstartinfo,我一直在阅读如何在C#ASP.NET应用程序中执行Win32命令行程序,由于某种原因,下面的代码在执行过程中永远不会完成,会无限期地卡在output=p.StandardOutput.ReadToEnd()上行 ProcessStartInfo info = new ProcessStartInfo(@"FetchIntranetPageSpecial.exe"); info.Arguments = "hostname"; info.UseShellExecute = f
output=p.StandardOutput.ReadToEnd()上代码>行
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();
当从本地调试服务器执行代码时(在Visual Studio中按F5),代码运行良好,但当通过浏览器通过完整URL(myexample.com/testapp)访问代码时,调试器从未移动过输出=…
行
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
权限设置为“所有人,一切”——在通过本地主机访问时仍然可以正常工作,但在远程访问时仍然挂起
有没有关于我下一步可以尝试的建议
编辑:我也阅读了这一页,但在这种情况下,调试器会在这一行进入不确定的“等待”状态:
while (read.Peek() >= 0) // stuck on this line
Console.WriteLine(read.ReadLine());
您如何在生产环境中托管您的应用程序?您的进程
代码是否与另一个可执行文件协同工作?@oleksii它在IIS/Windows Server 2008 R2下运行,封装在具有自己应用程序池的应用程序中。需要澄清的是,当代码仍在同一文件夹中时,问题会再次出现。当我按F5运行它时,它工作。当我通过myexample.com/testapp访问它来运行它时,它永远不会超过read()行。您的cmd程序是否对CurrentDirectory进行了假设?我也会将该过程放入using语句中。