我可以从c#winform应用程序挂钩c ++控制台应用程序吗?
问题描述:
我试过输出控制台的给定代码来Winform应用程序它仅在控制台退出时输出。我试图挂钩是一个C ++控制台应用程序。
I Tried The Given Code To Output A Console To Winform Application It Outputs only when the console exits.Console I try to hook is a C++ console application.
//C# code to run a console exe and update in my Winform
Process proc = new Process();
// Redirect the output stream of the child process.
string startupPath = System.IO.Directory.GetCurrentDirectory();
proc.StartInfo.UseShellExecute = false;
proc.OutputDataReceived += p_OutputDataReceived;
proc.StartInfo.FileName = startupPath+"\\Application1.exe";
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.EnableRaisingEvents = true;
proc.StartInfo.CreateNoWindow = true;
// see below for output handler
proc.ErrorDataReceived += p_OutputDataReceived;
proc.Start();
proc.BeginErrorReadLine();
proc.BeginOutputReadLine();
private void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
//MessageBox.Show(e.Data);
this.Invoke((MethodInvoker)delegate
{
if(e.Data!=null)
this.listBox1.Items.Add(e.Data);
});
}
//Application1.exe是从1到100的C ++控制台打印每行。
//如果应用程序是ac,我的列表框会实时更新#Console应用程序
//Application1.exe is a C++ console printing from 1 to 100 in each line.
//My Listbox updates in real time if the application is a c# Console application