System.Diagnostics.Process pro = new System.Diagnostics.Process();
pro.StartInfo.FileName = "cmd.exe";
pro.StartInfo.UseShellExecute = false;
pro.StartInfo.RedirectStandardError = true;
pro.StartInfo.RedirectStandardInput = true;
pro.StartInfo.RedirectStandardOutput = true;
pro.StartInfo.CreateNoWindow = true;
pro.Start();
pro.StandardInput.WriteLine(command);
pro.StandardInput.WriteLine("exit");
pro.StandardInput.AutoFlush = true;
string output = pro.StandardOutput.ReadToEnd();
//获取cmd窗口的输出信息
pro.WaitForExit();//等待程序执行完退出进程
pro.Close();
WaitForExit()方法可能会发生死锁。