2012-02-04 3 views
0

C# Windows Form 응용 프로그램에 C++ 콘솔의 출력을 가져 오려고하는데 문제가있는 것은 C++ exe가 C# 콘솔에 출력 된 것입니다. C++ exe가 종료되었습니다. 어쨌든 exe를 끝내지 않고 C++ exe를 실행하면서 실시간으로 C# 콘솔에 exe 출력을 얻으려고합니까? 여기 는C# 콘솔 출력을 C#으로 리디렉션

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); 

감사합니다,

답변

1

사용 OutputDataReceived 이벤트 :

, 내 대답은 정확히 같은
+0

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(); 
했다 그러나 나는 너무 느렸다. – Bazurbat

+0

감사합니다 맥스, 그것은 잘 OutputDataReceived 함께 작동합니다. 그러나 C# 콘솔로 출력을 얻는 경우 성능이 상당히 느려지지만 괜찮습니다. – Anshu

관련 문제