Я разработал веб-страницу ASP.NET C #, которая подключается к командной строке удаленного компьютера с помощью PSSERVICES.exe и выполняет некоторые команды для серверов. Выполнение работает нормально, пока я не развернул приложение на IIS 7.5. Приложение должно запускать команды, получать результат и отображать его пользователю. После развертывания выполнение команды имеет странное поведение, поскольку команда никогда не завершается, кажется, что приложение входит в бесконечный цикл, и результат команды никогда не возвращается.
строка output = ""; строка error = ""; string filePath = @ "C: \" + area.Name + ""+ area.Server.Name +""+ действие +" .txt "; UpdateXML_History update_History = новый UpdateXML_History ();
Process p;
p = new System.Diagnostics.Process();
//Do not receive an event when the process exits.
p.EnableRaisingEvents = false;
/* Init Structure */
CommandsLog _commandlog = new CommandsLog();
_commandlog.StartDateTime = DateTime.Now;
_commandlog.Command = action + " service " + service;
_commandlog.Status = CommandStatus.NOTSTARTED;
_commandlog.Output = "";
/*****************/
//The "/C" Tells Windows to Run The Command then Terminate
ProcessStartInfo PSI = new ProcessStartInfo();
PSI.FileName = @"psService.exe";
PSI.RedirectStandardInput = true;
PSI.RedirectStandardOutput = true;
PSI.RedirectStandardError = true;
PSI.UseShellExecute = false;
PSI.CreateNoWindow = true;
PSI.WindowStyle = ProcessWindowStyle.Hidden;
PSI.Arguments = @"\\" + area.Server.Name + " -u " + DomainUser.userDomain + "\\" + DomainUser.userName + " -p " + DomainUser.password + " " + action + @" """ + service + " " + area.Name + @"""";
p.StartInfo = PSI;
p.Start();
_commandlog.Status = CommandStatus.RUNNING;
output = p.StandardOutput.ReadToEnd().ToString();
error = p.StandardError.ReadToEnd().ToString();
p.WaitForExit();
if (p.HasExited)
{
}
p.Close();
_commandlog.Status = CommandStatus.COMPLETE;
_commandlog.Output = output + " " + error;
_commandlog.EndDateTime = DateTime.Now;
// Update xml file
update_History.UpdateXML(area, _commandlog);
return output + " " + error;
В режиме отладки выполнение застревает в этом методе. Когда он достигнет p.WaitForExit (); он возвращается к коду и бесконечно выполняет команду.
Этот метод вызывается из контроллера webApi под названием CommandController:
[AcceptVerbs("GET", "POST")]
public Task<string> runCommand(CommandParamsViewModel commandParams)
{
return Task.Run(() =>
{
return ServicePsServicesUtil.LaunchService(...);
});
}
Я переключился на задачу вместо простой строки, но они оба не работают. Я не знаю, есть ли способ разрешить IIS 7.5 выполнять удаленные команды с помощью PsExec или PsService? Пожалуйста, мне нужна твоя помощь. Спасибо !