Process类有一个StartInfo属性,这个是ProcessStartInfo类.
Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; //设定程序名 p.StartInfo.UseShellExecute = false; //关闭Shell的使用 p.StartInfo.RedirectStandardInput = true; //重定向标准输入 p.StartInfo.RedirectStandardOutput = true; //重定向标准输出 p.StartInfo.RedirectStandardError = true; //重定向错误输出 p.StartInfo.CreateNoWindow = true; //设置不显示窗口 p.Start(); //启动进程 p.StandardInput.WriteLine("ping www.baidu.com ");//输入要执行的命令 p.StandardInput.WriteLine("exit"); //按钮控件的单击事件代码如下: private void button1_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("cmd.exe", "ping www.baidu.com "); }