C#中利用process類調用外部程序以及執行dos命令

c#中的Process類可方便的調用外部程序,所以我們可以通過調用cmd.exe程序 
加入參數 "/c " + 要執行的命令來執行一個dos命令 
(/c代表執行參數指定的命令後關閉cmd.exe /k參數則不關閉cmd.exe) 
 
 Process p = new Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.Arguments = "/k "+"命令";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.CreateNoWindow = false;
            p.Start();
            Response.Write(p.StandardOutput.ReadToEnd());
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章