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);
}
}
}
https://muzizongheng.blog.csdn.net/