How to use cmd with C#

    private string ExecuteCommand(string command)
    {
        ProcessStartInfo startInfo = new ProcessStartInfo() 
        {
            FileName = "cmd.exe",               
            UseShellExecute = false,
            CreateNoWindow = true,
            RedirectStandardInput = true,
            RedirectStandardOutput = true
        };

        var myProcess = Process.Start(startInfo);
        myProcess.StandardInput.WriteLine(command);
        myProcess.StandardInput.WriteLine("Exit");
        string output = myProcess.StandardOutput.ReadToEnd();        
        myProcess.Close();
        return output;
    }
原文地址:https://www.cnblogs.com/sanmao_net/p/2469709.html