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