首页 > 编程语言 > 详细

c#执行bat批处理文件,并通过线程将结果显示在控件中

时间:2016-08-23 20:16:37      阅读:208      评论:0      收藏:0      [点我收藏+]

核心代码如下:

   

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执行

c#执行bat批处理文件,并通过线程将结果显示在控件中

原文:http://www.cnblogs.com/oracleblogs/p/5800573.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!