zoukankan      html  css  js  c++  java
  • C#执行批处理命令

    using System.Diagnostics ;

    using System.IO;

    private void btnRun_Click(object sender, EventArgs e)
            {
                txtResult.Text = "";
                processCommand("Ping.exe", this.txtAddress.Text);
                processCommand("Ping.exe", this.txtAddress.Text);
            }

            public void processCommand(string commandName, string argument)
            {
                ProcessStartInfo start = new ProcessStartInfo(commandName);//设置运行的命令行文件问ping.exe文件,这个文件系统会自己找到
                //如果是其它exe文件,则有可能需要指定详细路径,如运行winRar.exe
                start.WorkingDirectory = "d:\360Downloads\";
                start.Arguments = argument;//设置命令参数
                start.CreateNoWindow = true;//不显示dos命令行窗口
                start.RedirectStandardOutput = true;//
                start.RedirectStandardInput = true;//
                start.UseShellExecute = false;//是否指定操作系统外壳进程启动程序
                txtResult.AppendText(start.WorkingDirectory  + " ");
                Process p = Process.Start(start);
                StreamReader reader = p.StandardOutput;//截取输出流
                string line = reader.ReadLine();//每次读取一行
                while (!reader.EndOfStream)
                {
                    txtResult.AppendText(line + " ");
                    line = reader.ReadLine();
                }
                p.WaitForExit();//等待程序执行完退出进程
                p.Close();//关闭进程
                reader.Close();//关闭流
            }

  • 相关阅读:
    python-操作excel之openpyxl
    python之redis
    geetest滑动验证
    vue-cookies
    谷歌浏览器安装vue插件
    axios和vuex
    概率论基础:补充(1)概率的公理化定义与随机变量的概念
    卸载 Anaconda 转用 Miniconda
    傅立叶变换
    SL-主成分分析(PCA)
  • 原文地址:https://www.cnblogs.com/wwwzzg168/p/3570108.html
Copyright © 2011-2022 走看看