星空网 > 软件开发 > ASP.net

c#中重定向windows控制台程序的输出信息

这个问题来自论坛提问,答案如下.这只是一个简单的ipconfig命令.如果是复杂的,比如oracle的exp之类的命令,能在调用的时候显示出来,还是相当酷的.

 using System; using System.Windows.Forms; namespace WindowsApplication8 {   public  partial  class Form1 : Form   {     public Form1()     {       InitializeComponent();     }      delegate  void dReadLine( string strLine);     private  void excuteCommand( string strFile, string args, dReadLine onReadLine)     {       System.Diagnostics.Process p =  new System.Diagnostics.Process();       p.StartInfo =  new System.Diagnostics.ProcessStartInfo();       p.StartInfo.FileName = strFile;       p.StartInfo.Arguments = args;       p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;       p.StartInfo.RedirectStandardOutput =  true ;       p.StartInfo.UseShellExecute =  false ;       p.StartInfo.CreateNoWindow =  true ;       p.Start();       System.IO.StreamReader reader = p.StandardOutput; // 截取输出流        string line = reader.ReadLine(); // 每次读取一行        while ( ! reader.EndOfStream)       {         onReadLine(line);         line = reader.ReadLine();       }       p.WaitForExit();     }      private  void button1_Click( object sender, EventArgs e)     {       excuteCommand( " ipconfig " , "" , new dReadLine(PrintMessage));     }      private  void PrintMessage( string strLine)     {       this .textBox1.Text += strLine +  " " ;     }   } }/* 何问起 hovertree.com */

推荐:http://www.cnblogs.com/roucheng/p/3521864.html




原标题:c#中重定向windows控制台程序的输出信息

关键词:C#

C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

有物流到全南:https://www.goluckyvip.com/tag/98233.html
空运物流:https://www.goluckyvip.com/tag/98234.html
到印尼的物流:https://www.goluckyvip.com/tag/98235.html
到印尼物流:https://www.goluckyvip.com/tag/98236.html
航空快递物流:https://www.goluckyvip.com/tag/98237.html
黑龙江到海南物流:https://www.goluckyvip.com/tag/98238.html
一夜之间大批卖家货物被偷,又迎大量Listing将被下架!跨境赚钱"好日子"到头了?:https://www.goluckyvip.com/news/220219.html
晚上沈阳市区哪里好玩的地方 晚上沈阳有什么好玩的地方:https://www.vstour.cn/a/410235.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流