博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

核心代码如下:

   

Process p = new Process();
p.StartInfo.FileName = filePath;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
string txt = p.StandardOutput.ReadToEnd();
this.textBox1.Invoke(new EventHandler(delegate
{
this.textBox1.Text +="\r\n"+ txt;
}));
p.WaitForExit();
p.Close();
p.Dispose();

this.textBox1.Invoke(new EventHandler(delegate
{
this.textBox1.Text += "\r\n\r\n文件(" + filePath + ")执行结束";
}));

 

 

因为批处理文件时在线程里处理的,所以处理控件的时候需要invoke执行