Process prc=new Process();
prc.StartInfo.FileName="cmd.exe";
prc.StartInfo.UseShellExecute=false;
prc.StartInfo.RedirectStandardInput = true;
prc.StartInfo.RedirectStandardOutput = true;
prc.StartInfo.RedirectStandardError = true;
// prc.StartInfo.CreateNoWindow = true;
prc.Start();
prc.StandardInput.WriteLine("ping 10.1.0.1");
prc.StandardInput.WriteLine("exit");
prc.StandardInput.Close();
prc.StandardOutput.ReadToEnd();
我这样写什么信息都看不到,也不知道程序到底运行了没有

解决方案 »

  1.   

    http://www.kmov.com.cn/dispbbs.asp?boardid=5&id=12519&page=1
      

  2.   

    调用页面后是在客户端Ping,而不是在服务端ping吧?
      

  3.   

    把ping的结果写入文本文件,然后读文本文件试试
      

  4.   

    you didn't write the output out, how do you know what happend?? Process prc=new Process();
    prc.StartInfo.FileName="cmd.exe";
    prc.StartInfo.UseShellExecute=false;
    prc.StartInfo.RedirectStandardInput = true;
    prc.StartInfo.RedirectStandardOutput = true;
    prc.StartInfo.RedirectStandardError = true;
    prc.StartInfo.CreateNoWindow = false;
    prc.Start();
    prc.StandardInput.WriteLine("ping 127.0.0.1");
    prc.StandardInput.Close();
    Response.Write(prc.StandardOutput.ReadToEnd());
      

  5.   

    .net2.0下有专门的一个类处理这个。
      

  6.   

    我现在从数据库里提取IP数据循环执行,但是好像出现没什么反映的现象,应该从哪儿执行循环呢?
    string sql="select eqname,addr,ip from eq order by eqid desc";
    DataTable dt=universal.sd.rdTable(sql);
    DataColumn fullTitle = new DataColumn("rst");
    fullTitle.DataType=System.Type.GetType("System.String");
    dt.Columns.Add(fullTitle);
    string strRst;
    foreach(DataRow dr in dt.Rows)
    {
    Process prc=new Process();
    prc.StartInfo.FileName="cmd.exe";
    prc.StartInfo.UseShellExecute=false;
    prc.StartInfo.RedirectStandardInput = true;
    prc.StartInfo.RedirectStandardOutput = true;
    prc.StartInfo.RedirectStandardError = true;
    prc.StartInfo.CreateNoWindow = true;
    prc.Start();
    prc.StandardInput.WriteLine("ping -n 1 "+dr["ip"].ToString());
    prc.StandardInput.WriteLine("exit");
    strRst=prc.StandardOutput.ReadToEnd();
    if(strRst.IndexOf("(0% loss)")!=-1)  strRst = "连接";  else if( strRst.IndexOf("Destination host unreachable.")!=-1)  strRst = "无法到达目的主机";  else if(strRst.IndexOf("Request timed out.")!=-1)  strRst = "超时";  else if(strRst.IndexOf("Unknown host")!=-1)  strRst = "无法解析主机"; 


    prc.Close(); 
    dr["rst"]=strRst;
    }
    dt.AcceptChanges();
    dg.DataSource=dt;
    dg.DataBind();
      

  7.   

    ====================================
    you didn't write the output out, how do you know what happend?? Process prc=new Process();
    prc.StartInfo.FileName="cmd.exe";
    prc.StartInfo.UseShellExecute=false;
    prc.StartInfo.RedirectStandardInput = true;
    prc.StartInfo.RedirectStandardOutput = true;
    prc.StartInfo.RedirectStandardError = true;
    prc.StartInfo.CreateNoWindow = false;
    prc.Start();
    prc.StandardInput.WriteLine("ping 127.0.0.1");
    prc.StandardInput.Close();
    Response.Write(prc.StandardOutput.ReadToEnd());
    如果要执行关机,是否能把ping 127.0.0.1改成shutdown -s呢?
      

  8.   

    cmd里的命令如果有权限应该都能执行的吧
      

  9.   

    其实不需要这么麻烦,直接用Dos命令ping 127.0.0.1 >> D:\127.0.0.1.txt然后读取这个文件