需求:用process方法在后台启动ping命令 ping www.baidu.com -t ,并获取命令的返回结果。
如:Minimum = 46ms, Maximum = 48ms, Average = 47ms遇到的问题:主界面一直假死状态,如何解决,谢谢。
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();//关闭流
如:Minimum = 46ms, Maximum = 48ms, Average = 47ms遇到的问题:主界面一直假死状态,如何解决,谢谢。
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();//关闭流
new Microsoft.VisualBasic.Devices.Computer().Network.Ping("www.baidu.com");
返回Boolean型。