Process p = new Process();p.StartInfo.FileName = "cmd.exe"; //設定程序名p.StartInfo.Arguments = "/c " command; //設定程式執行參數p.StartInfo.UseShellExecute = false; //關閉Shell的使用p.StartInfo.RedirectStandardInput = true; //重定向標準輸入p.StartInfo.RedirectStandardOutput = true; //重定向標準輸出p.StartInfo.RedirectStandardError = true; //重定向錯誤輸出p.StartInfo.CreateNoWindow = true; //設置不顯示窗口 p.Start(); //啟動//p.StandardInput.WriteLine(command); //也可以用這種方式輸入要執行的命令//p.StandardInput.WriteLine("exit"); //不過要記得加上Exit要不然下一行程式執行的時候會當機return p.StandardOutput.ReadToEnd(); //從輸出流取得命令執行結果 相关文章: 2021-05-17 2021-07-28 2022-01-01 2021-08-10 2022-01-30 2021-10-06 2022-12-23