• 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();
            }
  • 相关阅读:
    Kanzi Studio中的概念
    Linux基本操作1
    Kanzi入门
    Kanzi UI Solution
    Linux下内存占用和CPU占用的计算
    AD19新功能之交互式等长
    AD19新功能之跟随走线
    AD19新功能之Gloss Selected(修线)
    AD19新功能之ActiveRoute
    RT-Thread--内核移植
  • 原文地址:https://www.cnblogs.com/yanjinliang/p/5972047.html
Copyright © 2020-2023  润新知