c#程序执行cmd命令
private void ExecuteCMD(string cmd)
{
Process process = new Process();
try
{
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
// process.StartInfo.CreateNoWindow = true;
process.Start();
process.StandardInput.WriteLine(cmd);
process.StandardInput.WriteLine("exit");
process.WaitForExit();
string readProOutResult = process.StandardOutput.ReadToEnd();
}
catch (Exception ex)
{
MessageBox.Show("操作失败");
}
finally
{
process.Close();
}