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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM