将C ++控制台输出重定向到C#

我正在尝试将C ++控制台的输出提供给C#Windows窗体应用程序,我遇到的问题是C ++ exe的输出仅在C ++ exe终止后显示在C#控制台中。 有没有在运行C ++ exe时实时获取exe输出到C#控制台(如不必终止exe)? 这是我试过的方式,

Process p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = "C:\\path\\ABC.exe"; p.Start(); string output = p.StandardOutput.ReadToEnd(); Console.WriteLine(output); 

谢谢,

使用OutputDataReceived事件:

 Process p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = "C:\\path\\ABC.exe"; p.OutputDataReceived += (s, e) => Console.WriteLine(e.Data); p.Start(); p.BeginOutputReadLine(); 

请参阅Console.SetIn() (和SetOut)和Process.StandardOutput