日期:2014-05-18 浏览次数:20793 次
Process info = new Process(); info.StartInfo.FileName = "cmd.exe"; //info.StartInfo.Arguments = " ping 61.139.2.69 -t"; info.StartInfo.CreateNoWindow = true;//不显示dos命令行窗口 info.StartInfo.UseShellExecute = false; info.StartInfo.RedirectStandardInput = true; info.StartInfo.RedirectStandardOutput = true; info.Start(); info.StandardInput.WriteLine("ping www.baidu.com -t"); StreamReader sr = info.StandardOutput; StreamReader reader = info.StandardOutput;//截取输出流 string strLine = reader.ReadLine();//每次读取一行 while (!reader.EndOfStream) { tbResult.AppendText(strLine + " "); strLine = reader.ReadLine(); } info.WaitForExit();//等待程序执行完退出进程 info.Close();//关闭进程 reader.Close();//关闭流