如何使用隐藏的CMD从c#运行CMD

sar*_*i k 3 c#

如何在没有看到cmd窗口的情况下从c#运行CMD?

Dav*_*und 7

ProcessStartInfo那里有一个叫做的参数CreateNoWindow

public static string ExecuteCommand(string command) {

    ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + command)
        {
            RedirectStandardError = true,
            RedirectStandardOutput = true,
            UseShellExecute = false,
            CreateNoWindow = true
        };

    using (Process proc = new Process())
    {
        proc.StartInfo = procStartInfo;
        proc.Start();

        string output = proc.StandardOutput.ReadToEnd();

        if (string.IsNullOrEmpty(output))
            output = proc.StandardError.ReadToEnd();

        return output;
    }

}
Run Code Online (Sandbox Code Playgroud)