C# 程序一個cmd命令窗口執行多條dos命令

1,前幾天的項目要用到程序執行dos命令去編譯已生成的ice文件,後來去百度了好多都是隻能執行一條命令html

    或者是分別執行幾條命令,而我要的是一條dos命令在另外一臺命令的基礎上執行。而不是分別執行。htm

   後來嘗試了好屢次才弄好,總結以下,怕之後忘記。對象

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;
         }

  轉發自:https://www.cnblogs.com/visibleisfalse/p/3578886.htmlblog

相關文章
相關標籤/搜索