c# 调用ping命令遇到的问题 像这样的问题 你直接百度也就出来了` 调用它的exit 退出控制台 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 p.StandardInput.WriteLine("exit"); 我已经调用了 static void Main(string[] args) { string ip = "202.114.187.23"; string strRst = CmdPing(ip); Console.WriteLine(strRst); } private static string CmdPing(string strIp) { Process p = new Process(); p.StartInfo.FileName = "ping.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.StartInfo.Arguments = strIp; string pingrst; p.Start(); pingrst = p.StandardOutput.ReadToEnd(); p.Close(); return pingrst; } 为什么要调用cmd? 直接用ping不就得了? 谢谢4楼的哈 不过我把你代码完全复制过来。运行还是好多进程ping.exe,而且过一会输入的都是空格。没有内容 ,ping.exe进程也全没了 pingrst = p.StandardOutput.ReadToEnd(); p.WaitForExit();p.Close(); System.Net.NetworkInformation命名空间下的Ping类,对Ping功能提供了直接支持。不必使用Process类进行外部命令调用。 100分求图像保存问题 顶者有分 c#中怎么用程序实现regsvr32的功能? C#怎样打开word文档? 求助:关于查询的问题: 用SELECT查询时出了问题怎么搞?? 在C#中结构体如何使用? datagrid 一个送分问题:web form中的html中如何访问web窗体中的Text控件,document.Form1.下没有TextUserName,如何访问呢?在线等待 如何写帮助?再线等待? 急救!!! 为什么用c#做出来的程序在别的机器上无法运行? mono linux C# asp.net网站如何对一组控件赋值(VB语句)
static void Main(string[] args)
{
string ip = "202.114.187.23";
string strRst = CmdPing(ip); Console.WriteLine(strRst);
} private static string CmdPing(string strIp)
{ Process p = new Process(); p.StartInfo.FileName = "ping.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = strIp; string pingrst; p.Start(); pingrst = p.StandardOutput.ReadToEnd();
p.Close(); return pingrst; } 为什么要调用cmd? 直接用ping不就得了?
不过
我把你代码完全复制过来。运行还是好多进程ping.exe,而且过一会输入的都是空格。没有内容 ,ping.exe进程也全没了
p.WaitForExit();
p.Close();