zoukankan      html  css  js  c++  java
  • C# cmd执行命令

    CMD命令执行
    ///<summary>
            /// cmd命令执行,在cmd上可以执行的语句,直接传到这里,调用grads画图实例如下:
            ///  Cmd("C:/OpenGrADS/Contents/Cygwin/Versions/2.0.1.oga.1/i686/grads.exe -lbcx 'D:/data_wrfchem/gs/d01_hour_pm25.gs D:/data_wrfchem 2016-04-18 d01'");
            ///  Cmd("grads启动程序exe路径 -lbcx 'gs脚本文件 参数1 参数2 参数3'");
            /// </summary>
            /// <param name="c">执行语句</param>
            public void Cmd(string c)
            {
                System.Diagnostics.Process process = new System.Diagnostics.Process();
                process.StartInfo.FileName = "cmd.exe";
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.CreateNoWindow = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardInput = true;
                process.Start();
                process.StandardInput.WriteLine(c);
                process.StandardInput.AutoFlush = true;
                process.StandardInput.WriteLine("exit");
                StreamReader reader = process.StandardOutput;//截取输出流
                string output = reader.ReadLine();//每次读取一行
                while (!reader.EndOfStream)
                {
                    // PrintThrendInfo(output);
                    output = reader.ReadLine();
                }
                process.WaitForExit();
            }
  • 相关阅读:
    nginx一键安装脚本
    nginx动静分离之后,设置默认主页
    日志备份
    cc高防主机部署
    原型和原型链
    Git&Github分支
    Git&Github基础
    传输层协议TCP&UDP
    本地库与远程库交互
    SVG
  • 原文地址:https://www.cnblogs.com/yanjinliang/p/5972047.html
Copyright © 2011-2022 走看看