I'm creatin application(C#) that need run another app. This. app is game(C++,Directx7,GDI, I don't have source) that show console window for debugging from dll(static). For show console window this dll has this lines:
AllocConsole();
freopen("CONIN$","rb",stdin);
freopen("CONOUT$","wb",stdout);
freopen("CONOUT$","wb",stderr);
In my 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. 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
private static void ReadOutput(object sender, DataReceivedEventArgs e)
{
if (e.Data != null)
{
//your output here
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.