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();
arrow
arrow
    文章標籤
    C# cmd.exe process
    全站熱搜

    西夏普 發表在 痞客邦 留言(1) 人氣()