我可以从c#winform应用程序挂钩c ++控制台应用程序吗? [英] Can I hook a c++ console application from a c# winform application?

查看:96
本文介绍了我可以从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

推荐答案

参见http://msdn.microsoft.com/en-us/library /system.diagnostics.processstartinfo.redirectstandardoutput(v=vs.110).aspx [ ^ ]。


这篇关于我可以从c#winform应用程序挂钩c ++控制台应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆