0

我正在执行一个位于远程服务器上的 .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();

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

4

2 回答 2

0

你试过了 p.WaitForInputIdle();吗?

- - - - - - - 更新

GUI/非 GUI 的区别:如何判断进程是否具有图形界面?

于 2013-06-28T14:33:39.577 回答
0

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

于 2013-06-28T14:48:29.223 回答