我是要用程序获取到这个cmd窗口,然后读取窗口中的文本

解决方案 »

  1.   

       System.Diagnostics.Process p = new System.Diagnostics.Process();
       p.StartInfo.FileName="cmd.exe";
       p.StartInfo.UseShellExecute=false;
       p.StartInfo.RedirectStandardError=true;
       p.StartInfo.RedirectStandardInput=true;
       p.StartInfo.RedirectStandardOutput=true;
       p.StartInfo.CreateNoWindow=true;      //不显示命令行窗口
       p.Start();
       p.StandardInput.WriteLine("ping 127.0.0.1");    //输入要运行的命令
       p.StandardInput.WriteLine("exit");
       string strRst=p.StandardOutput.ReadToEnd();    //取得输出结果
      

  2.   

    如果是程序外打开的命令行窗口,则需要用PInvoke的方式调用Windows API. 先用Spy++捕捉窗口的信息.
    查找API在.NET中可用的形式, 可以到www.pinvoke.net.