private void readBack()
{
var process = new Process();
process.StartInfo.FileName = "XXXX.exe";
process.StartInfo.Arguments = "XXXXXXX";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived);
process.Start();
process.BeginOutputReadLine();
//process.WaitForExit();
}
//输出数据
private void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (!string.IsNullOrEmpty(e.data))
{
if (InvokeRequired)
{
Action action = () => richTextBox1.AppendText(e.data + "\r\n");
richTextBox1.Invoke(action);
}
else
{
richTextBox1.AppendText(e.data + "\r\n");
}
}
}
// btn code
private void button1_Click(object sender, EventArgs e)
{
BackgroundWorker bW = new BackgroundWorker();
bW.DoWork += (s, eb) =>
{
readBack();
};
bW.RunWorkerAsync();
}