你的位置:首页 > 软件开发 > ASP.net > c#中重定向windows控制台程序的输出信息

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

发布时间:2016-06-13 17:00:41
这个问题来自论坛提问,答案如下.这只是一个简单的ipconfig命令.如果是复杂的,比如oracle的exp之类的命令,能在调用的时候显示出来,还是相当酷的. using System; using System.Windows.Forms; namespace WindowsA ...

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

 using System; using System.Windows.Forms; namespace WindowsApplication8 {   public  partial  class Form1 : Form   {     public Form1()     {       InitializeComponent();     }      delegate  void dReadLine( get='_blank'>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 */

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

关键词:C#

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

可能感兴趣文章

我的浏览记录