为什么这段代码只显示 cmd 窗口而永远不会到达末尾?我想将 PsList 的输出输入到我的 C# 应用程序中。执行在这一行停止:“int exitCode = proc.ExitCode;”
private static void PsList()
{
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"C:\PsList.exe";
start.WindowStyle = ProcessWindowStyle.Hidden;
start.CreateNoWindow = true;
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using (Process proc = Process.Start(start))
{
proc.WaitForExit(4000);
int exitCode = proc.ExitCode;
string exitMsg = proc.StandardOutput.ReadToEnd();
}
}