c#中的Process類可方便的調用外部程序,所以我們可以通過調用cmd.exe程序
加入參數 "/c " + 要執行的命令來執行一個dos命令
(/c代表執行參數指定的命令後關閉cmd.exe /k參數則不關閉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());
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());