zoukankan      html  css  js  c++  java
  • C# 程序一个cmd命令窗口执行多条dos命令

    1,前几天的项目要用到程序执行dos命令去编译已生成的ice文件,后来去百度了好多都是只能执行一条命令

        或者是分别执行几条命令,而我要的是一条dos命令在另一台命令的基础上执行。而不是分别执行。

       后来尝试了好多次才弄好,总结如下,怕以后忘记。

     public void DoDos(string comd1,string comd2,string comd3)
            {
                string output = null;
                Process p = new Process();//创建进程对象 
                p.StartInfo.FileName = "cmd.exe";//设定需要执行的命令 
                // startInfo.Arguments = "/C " + command;//“/C”表示执行完命令后马上退出  
                p.StartInfo.UseShellExecute = false;//不使用系统外壳程序启动 
                p.StartInfo.RedirectStandardInput = true;//可以重定向输入  
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = false;//不创建窗口 
                p.Start();
               // string comStr = comd1 + "&" + comd2 + "&" + comd3;
                p.StandardInput.WriteLine(comd1);
                p.StandardInput.WriteLine(comd2);
                p.StandardInput.WriteLine(comd3);
              //  output = p.StandardOutput.ReadToEnd();
                if (p != null)
                {
                    p.Close();
                }
               // return output;
             }
    View Code
  • 相关阅读:
    KVC该机制
    JS多语种方式
    面试经典(1)---翻转字的顺序在一个句子
    正确Linux新手很实用20命令
    代码添加背景音乐的日记
    什么是比特币(Bitcoin)?
    李开复:该算法的重要性
    javascript推断的浏览器类型
    libyuv编
    Linux下将UTF8编码批量转换成GB2312编码的方法
  • 原文地址:https://www.cnblogs.com/visibleisfalse/p/3578886.html
Copyright © 2011-2022 走看看