C#調用windows命令行(CMD)


using System.Diagnostics;

public static void StartCmd(String command)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe"; //命令
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); //cmd執行的語句
//p.StandardOutput.ReadToEnd(); //讀取命令執行信息
p.StandardInput.WriteLine("exit"); //退出
}


免責聲明!

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



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