2012-04-26 6 views
0

콘솔에서 다른 콘솔로 제어/쓸 수 있습니까? Console.WriteLine을 테스트했지만 아무 일도 없었습니다. 어떤 도움을 주셔서 감사합니다. C# 콘솔 출력


나는 다른 클래스에서 콘솔에 쓰기 의미했다. 오해의 소지가 있음을 유감스럽게 생각합니다. 서버 클래스 (Server.cs)와 기본 클래스 (Program.cs)가 있습니다. 서버 클래스는 연결에 대한 정보를 콘솔에 쓰려고합니다.

+0

같은, 그것은 win32API에의합니다. – gdoron

+0

콘솔 리디렉션을 찾고 있습니까 http://msdn.microsoft.com/en-us/library/system.console.setout.aspx – corn3lius

+0

@ corn3lius. 콘솔은'TextReader'가 아닙니다. 그리고 그것은 정적입니다. 그래서 여러분은 그것을 어떻게 전달할 것입니까? ** ... ** – gdoron

답변

1

호출 콘솔에 쓰려면 응용 프로그램을 프로젝트 설정에서 Console 응용 프로그램으로 표시해야합니다. UI 애플리케이션에서 콘솔에 글을 쓰면 프로세스가 새로운 애플리케이션을 작성한 다음 작성합니다.

다른 기존 콘솔에 쓰고 싶다면 AttachConsole, WriteConsoleFreeConsole과 같은 Win32Api 기능에서 P-Invoke를 사용하여 가능할 수 있습니다. 내가 실수 아니에요 경우

0

, 당신은 내가 (나는 그것을 할 수 없습니다 믿는)가 수행 할 수 있습니다 _if_ 생각이

System.Diagnostics.Process p = new System.Diagnostics.Process(); 

p.StartInfo.FileName = "ModelExporter.exe"; 
p.StartInfo.RedirectStandardOutput = true; 
p.StartInfo.RedirectStandardInput = true; 
p.StartInfo.UseShellExecute = false; 
p.StartInfo.CreateNoWindow = true; 
p.Start(); 

StreamReader myStreamReader = p.StandardOutput; 

// Reads a single line of the programs output. 
string myString = myStreamReader.ReadLine(); 

// This would print the string to the DOS Console for the sake of an example. 
// You could easily set a textbox control to this string instead... 
Console.WriteLine(myString); 

p.Close();