使用程序来代替人工输入。看了一些例子
p.StandardInput.WriteLine("exit");
string strRst = p.StandardOutput.ReadToEnd();
执行exit后才能得到返回值,但这样程序就退出了。无法继续输入命令了!
-----------------------------------------------------------------------------
目的:登陆远程服务器,并运行远程服务器上的程序,根据程序执行的结果判断继续执行其他命令!谢谢!电信行业是java的天下……
p.StandardInput.WriteLine("exit");
string strRst = p.StandardOutput.ReadToEnd();
执行exit后才能得到返回值,但这样程序就退出了。无法继续输入命令了!
-----------------------------------------------------------------------------
目的:登陆远程服务器,并运行远程服务器上的程序,根据程序执行的结果判断继续执行其他命令!谢谢!电信行业是java的天下……
解决方案 »
- c#定时器无效了?
- datagridview中在选择框选中多行然后删除只能删除一行,怎么修改以下代码才可以删除选中的多行?
- 对象序列化问题-急
- Security Application Block 问题
- C#~~如何在datagridview显示checkedlistbox选中项内容
- 请问如何得到datagrid中某一行的各列值
- ComboBox绑定DataTable时绑定值为System.Data.DataView
- C#做的练习网站出错了,请指点
- 在调用printPreviewDialog对话框的时候,我想让对话框以最大化方式显示,同时让对话框的最大和最小化按钮不显示,如何实现?
- 求助,vs2010 同时打开两个C#创建的窗口项目就会崩溃
- 请问怎样给TableLayoutPanel加上一个Designer还能让它可以和使用者交互
- 请问怎么将EXCEL文件导入到DRID中,或者让他成生一个表也行
编写自己的IDE 如何在图形界面中实时捕获控制台程序的标准输出
http://www.contextfree.net/wangyg/b/tech/myide.html
和
ShellControl - A console emulation control
http://www.codeproject.com/cs/miscctrl/shellcontrol.asp
p.Start();// p.StandardInput.WriteLine("ping "+strIp);
//
//p.StandardInput.WriteLine("exit"); string strRst = p.StandardOutput.ReadToEnd(); Console.WriteLine(strRst); p.StartInfo.FileName = "cmd.exe "; p.StartInfo.Arguments = " /C dir "; p.Start(); strRst = p.StandardOutput.ReadToEnd(); Console.WriteLine(strRst); p.Close();
DOTNET程序获得输出不全.
当直接执行控制台程序,在控制台中输入命令,执行完成后为出现 "XXX>"提示符等待继续输入.
由于程序采用多线程执行,本想用 "XXX>"提示符号, 来判断命令是否执行结束.
如果程序执行后,获得该命令执行得到的返内容,在执行下一命令...
但DOTNET程序却无法获得这一符号.而java写的程序却都能得到.
谢谢?2.如何正确调用Telnet?
string fileName = @"c:\winnt\system32\telnet.exe";
p.StartInfo.Arguments = "192.168.1.5";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();但p.HasExited 却为 true
p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; string pingrst; p.Start();
// string strRst = p.StandardOutput.ReadToEnd(); p.StandardInput.WriteLine("ping -n 1 "+strIp); p.StandardInput.WriteLine("exit"); string strRst = p.StandardOutput.ReadToEnd(); if(strRst.IndexOf("(0% loss)")!=-1) pingrst = "SUCCES"; else if( strRst.IndexOf("Destination host unreachable.")!=-1) pingrst = "FAIL"; else if(strRst.IndexOf("Request timed out.")!=-1) pingrst = "TIME OUT"; else if(strRst.IndexOf("Unknown host")!=-1) pingrst = "UNKNOWN HOST"; else pingrst = strRst; p.Close(); return pingrst;
}
供樓住參考,著行以後的結果需要自己枚舉判斷的吧.
会处于堵塞状态。
应该用proc.StandardOutput.ReadBlock( buffer, 0, 1);(逐个字符读取)
当判断输出了提示符出发一个事件,在执行下一命令。第二个问题调用Telnet,这个还没解决不过考虑用socket非常感谢各位网友的帮助!
也感谢Yippee的热心帮助!
Yippee'blog
《Process.StandardOutput 属性》
http://www.shengfang.org/blog/p/ProcessStandardOutput.php
《VS.NET PROCESS 输入 输出 模拟 CMD》
http://www.shengfang.org/blog/p/vsnetprocesscmdinout.php