已得到了一个CMD窗口的句柄,怎么样可以获取该CMD窗口里的内容呢? 已得到了一个CMD窗口的句柄,怎么样可以获取该CMD窗口里的内容呢?该CMD窗口的内容是: dir c: /s 输出的内容.我想即时逐行读取. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Process p = new Process();p.StartInfo.FileName = @"cmd.exe";p.StartInfo.CreateNoWindow = true;p.StartInfo.RedirectStandardOutput = true;p.StartInfo.RedirectStandardInput = true;p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;p.StartInfo.UseShellExecute = false;p.StartInfo.RedirectStandardError = true; try{ p.Start(); p.StandardInput.WriteLine("dir d:"); p.StandardInput.WriteLine("exit"); p.WaitForExit(); string output = p.StandardOutput.ReadToEnd(); p.Close(); Console.WriteLine("The following is the output\n"+output);}catch(System.Exception e){ Console.Out.WriteLine(e.Message);}Console.Out.WriteLine(p.StandardError.ReadToEnd());output里面是命令执行的结果。 不是这样!我要的那个CMD窗口,不是由我的软件执行的,是别的软件执行的.我可以得到 句柄.就是不知道怎么样可以得到内容 to 是别的软件执行的.我可以得到 句柄.就是不知道怎么样可以得到内容如果知道窗体句柄,可以通过API: GetWindowThreadProcessId 获得进程ID,参看http://www.pinvoke.net/default.aspx/user32/GetWindowThreadProcessId.html然后通过Process.GetProcessByID获得进程,最后通过上面的方法进行读取输出信息即可。 api -->GetWindowText??-----------这个不行。大家来思考一下,如何解决类似telnet的命令,这类命令的特点:与用户有交互。 telnet的交互与显示,是telnet自己处理的。楼主的,是自己处理别人的,没有可比性吧? call apims-help://MS.MSDNQTR.2003FEB.2052/dllproc/base/console_buffer_security_and_access_rights.htm DX控件高手请帮帮我(dxgridview的列的数据验证) C# 自定义属性的问题? 如何把下面的一个C结构改成C#版的啊 怎样将内存流中内容保存到一个文件中? 关于读取XML的值 关于DLL窗体。(高手请进) dataGridView删除行的问题 谁能给我一个好看点的.net登陆界面??? 一个简单的时间问题,高手快来,高分抢了. 谁能具一个垃圾收集的例子,越简单越好? 在C#中如何获取短文件名? 有关TextBox中String换行的问题
p.StartInfo.FileName = @"cmd.exe";p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
try
{
p.Start();
p.StandardInput.WriteLine("dir d:");
p.StandardInput.WriteLine("exit");
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd();
p.Close();
Console.WriteLine("The following is the output\n"+output);
}
catch(System.Exception e)
{
Console.Out.WriteLine(e.Message);
}
Console.Out.WriteLine(p.StandardError.ReadToEnd());output里面是命令执行的结果。
我要的那个CMD窗口,不是由我的软件执行的,
是别的软件执行的.我可以得到 句柄.
就是不知道怎么样可以得到内容
就是不知道怎么样可以得到内容如果知道窗体句柄,可以通过
API: GetWindowThreadProcessId
获得进程ID,
参看
http://www.pinvoke.net/default.aspx/user32/GetWindowThreadProcessId.html然后通过Process.GetProcessByID获得进程,
最后通过上面的方法进行读取输出信息即可。
-----------这个不行。大家来思考一下,如何解决类似telnet的命令,这类命令的特点:与用户有交互。
ms-help://MS.MSDNQTR.2003FEB.2052/dllproc/base/console_buffer_security_and_access_rights.htm