C# 获取Console的输入和输出 数据 (异步)

 

using System ;
using System .Diagnostics;
using System .IO;
 
class Program
{
    static void Main()
    {
        //
        // Setup the process with the ProcessStartInfo class.
        //
        ProcessStartInfo start = new ProcessStartInfo();
        start.FileName = @"D:\xxxxxxxxx\xxxxxxxxxxxxxxxxx.exe"; // Specify exe name.
        start.UseShellExecute = false;
        start.RedirectStandardOutput = true;
 
        //
        // Start the process.
        //
        using (Process process = Process.Start (start))
        {
            process.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived );
 
            process.BeginOutputReadLine ();
 
            process.WaitForExit ();
        }
    }
 
    static void process_OutputDataReceived( object sender , DataReceivedEventArgs e)
    {
        if (null != e)
        {
            Console.WriteLine (e. Data);
        }
    }
}
  
posted @ 2013-07-03 11:42  muzizongheng  阅读(1530)  评论(0编辑  收藏  举报
如果我们时时忙着展现自己的知识, 将何从忆起成长所需的无知?