0

我的代码:

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.FileName = Environment.CurrentDirectory + @"\PsExec\PsExec.exe";
p.StartInfo.Arguments = @"\\server-0 cmd /c wmic process get description,executablepath";
p.Start();
string output = p.StandardOutput.ReadToEnd();
string errormessage = p.StandardError.ReadToEnd();
p.WaitForExit();

控制台窗口不会自行关闭。当我手动关闭它时,我看到(在输出中):

Description             ExecutablePath                                             

我没有看到任何其他线路!但是如果我在控制台中写同样的:

psexec \\server-0 cmd /c wmic process get description,executablepath

我懂了:

Description             ExecutablePath
System Idle Process
System
smss.exe
csrss.exe               C:\Windows\system32\csrss.exe
wininit.exe             C:\Windows\system32\wininit.exe
csrss.exe               C:\Windows\system32\csrss.exe
...

我尝试了一些想法,例如:Thread.Sleep(...),每行阅读,,-accepteula/ EnableRaisingEventsOutputDataReceived它不调用),-d 标志(无输出),UseShellExecute=true(有效,但我无法隐藏控制台窗口)...

为什么我只收到第一行(在上面的 C# 代码中)?我应该更改哪些内容才能收到我在控制台中看到的相同内容?

对不起英语不好。感谢您的回答。

4

1 回答 1

-1

使用委托。接收到输出的上升事件并捕获数据。我也这样做了

于 2017-06-08T11:15:49.060 回答