How to start CMD from C # with hidden CMD

How to start CMD from C # without viewing cmd windows?

+3
source share
1 answer

There ProcessStartInfois a parameter namedCreateNoWindow

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;
    }

}
+7
source

Source: https://habr.com/ru/post/1773586/