I tried to use ruby Net::Telnet to connect windows 2008 and execute some commands. But it failed.
if execute
tn = Net::Telnet::new("Host"=>"walnutserver","Port"=>2300,"Prompt"=> /C:.*>/)
tn.login("user","pass")
tn.cmd("dir")
tn.cmd("dir")
the first tn.cmd("dir")
is success but the second one throws exceptions.And then subsequent commands all failed. After experimenting,I found that any windows command will cause this.
Exceptions:
Timeout::Error: timed out while waiting for more data
from c:/troy/data/chef/chef-client11/chef/embedded/lib/ruby/1.9.1/net/telnet.rb:558:in `waitfor'
from c:/troy/data/chef/chef-client11/chef/embedded/lib/ruby/1.9.1/net/telnet.rb:697:in `cmd'
from (irb):20
from c:/troy/data/chef/chef-client11/chef/embedded/bin/irb:12:in `<main>'
use sock.sysread() method to read responding, I found that terminal is blocked and display dir
0x00More?
Buf if execute
tn = Net::Telnet::new("Host"=>"walnutserver","Port"=>2300,"Prompt"=> /C:.*>/)
tn.login("user","pass")
tn.cmd("ls")
tn.cmd("uname")
It't running normally. ls
、uname
are some linux commands brought by chef which installed in target machine.
ruby version:ruby 1.9.3p286 (2012-10-12) [i386-mingw32]
I found someone else
asking the same question on Stackoverflow, but he didn't get the solution. http://www.ruby-forum.com/topic/1516840
Need your help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…