zoukankan      html  css  js  c++  java
  • c#执行bat批处理文件,并通过线程将结果显示在控件中

    核心代码如下:

       

    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 +=" "+ txt;
    }));
    p.WaitForExit();
    p.Close();
    p.Dispose();

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

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

  • 相关阅读:
    细菌 状态压缩
    素数
    骑士问题(knight)
    魔法石的诱惑
    平面上的最接近点对
    救援行动(save)
    优先队列
    leetcode 92. 反转链表 II
    leetcode 91. 解码方法
    leetcode 39. 组合总和
  • 原文地址:https://www.cnblogs.com/oracleblogs/p/5800573.html
Copyright © 2011-2022 走看看