1.前言
透過程式控制,可在背景執行cmd.exe的命令。
2.說明
程式碼,提供兩種方式執行命令:
//程式碼最少,但是會跳出DOS視窗,閃一下後自行關閉
System.Diagnostics.Process.Start("cmd.exe", @"/c dir");
//在背景執行,無DOS視窗閃爍問題
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = @"/c dir";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
文章標籤
全站熱搜

超棒~~ //在背景執行,無DOS視窗閃爍問題 <- 解決我的問題 : )