从远程执行的.exe获取响应

本文关键字:exe 获取 响应 执行 程执行 | 更新日期: 2023-09-27 18:20:21

我正在执行一个位于远程服务器上的.exe,但是PsExec似乎挂起了,并且本地服务没有退出。.exe确实在服务器上成功运行,但当它完成时,我希望本地服务退出。

这是我在atm上的代码:

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.FileName = @"C:'Program Files (x86)'PSTools'PsExec.exe";
p.StartInfo.Arguments = @"''<remote .exe path>";
p.Start();
//I have tried the following to exit the local service when a response is
//received but it still hangs.
//string output = p.StandardOutput.ReadToEnd();
//string errormessage = p.StandardError.ReadToEnd();
//p.WaitForExit();

远程服务完成后,我需要做什么才能退出本地服务?

从远程执行的.exe获取响应

您可以尝试使用-d选项运行psexec,建议用于非交互式应用程序。或者您可以在psexec上设置一个超时选项?

您尝试过p.WaitForInputIdle();吗?

-------------更新

GUI与非GUI的区别:如何判断流程是否有图形界面?