[英]Redirect from console window(C++ app) to textbox(C# app)
I'm creatin application(C#) that need run another app. 我是需要运行另一个应用程序的creatin应用程序(C#)。 This.
这个。 app is game(C++,Directx7,GDI, I don't have source) that show console window for debugging from dll(static).
应用程序是游戏(C ++,Directx7,GDI,我没有源代码),显示从dll(静态)调试的控制台窗口。 For show console window this dll has this lines:
对于show console window,这个dll有以下几行:
AllocConsole();
freopen("CONIN$","rb",stdin);
freopen("CONOUT$","wb",stdout);
freopen("CONOUT$","wb",stderr);
In my c# app. 在我的c#app中。 i want hide console window and redirect text from console window to textbox.
我想隐藏控制台窗口并将文本从控制台窗口重定向到文本框。 For hide console window i'm using winapi FindWindow , ShowWindow is not problem.
对于隐藏控制台窗口我正在使用winapi FindWindow , ShowWindow没有问题。 But how i can redirect text(output) from console window to textbox?
但是我如何将文本(输出)从控制台窗口重定向到文本框?
You can run your game using following code: 您可以使用以下代码运行游戏:
Process process = new Process();
process.StartInfo.FileName = "\"" + pathToGame + "\"";
//process.StartInfo.Arguments = args;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.UseShellExecute = false;
process.OutputDataReceived += new DataReceivedEventHandler(ReadOutput);
process.ErrorDataReceived += new DataReceivedEventHandler(ReadOutput);
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
//process.WaitForExit();
CL output and errors will go here CL输出和错误将在这里
private static void ReadOutput(object sender, DataReceivedEventArgs e)
{
if (e.Data != null)
{
//your output here
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.