I think I just figured out my own problem.  I needed to do a 
$stdout.flush after each command to update the console in an 
interactive manner.  Telnet now works as expected. Yeah!

On Aug 6, 2004, at 2:50 PM, Michael Hale wrote:

> Thanks for all the replies and suggestions.  They were very 
> encouraging.  Here is my code:
>
> require "net/telnet"
>
> def telnet_session(host_name, user, password, reboot=false)
> 	puts ""
> 	puts "****************************\\/"
> 	puts "started session #{host_name}\\/"
> 	puts "****************************\\/"
> 	puts ""
> 	
> 	host = Net::Telnet::new("Host" => host_name,
> 							"Output_log" => "output_log",
> 							"Timeout" => 300)
> 	
> 	host.login("LoginPrompt" => /Username[: ]*\z/n,
> 				"Name" => user,
> 				"Password" => password) {|c| print c }
> 	begin
> 		yield(host) if block_given?
> 	ensure
> 		begin
> 			if(reboot)
> 				host.cmd("String" => "reboot", "Prompt" => "")
> 			else
> 				#this should be smart enough to exit all the way out.
> 				host.cmd("String" => "exit", "Prompt" => "")
> 			end
> 		rescue Exception => e
> 			p e, 'Unable to exit/reboot.'
> 		ensure
> 			host.close
> 			
> 			# for some reason the telnet library on windows
> 			# needs some time to reset itself before I create another 
> conneciton.
> 			sleep 1
> 			
> 			puts ""
> 			puts "****************************/\\"
> 			puts "ended session #{host_name}  /\\"
> 			puts "****************************/\\"
> 			puts ""
> 		end
> 	end
> end
>
> debugLogIn = "debug"
> debugPassword = "passwd"
> ip = "192.168.2.54"
> 		
> telnet_session(ip, debugLogIn, debugPassword) {|host|
> 	host.cmd("con t") {|c| print c }
> 	sleep 1
> 	host.cmd("int m") {|c| print c }
> 	sleep 1		
> 	host.cmd("exit") {|c| print c }
> 	sleep 1
> 	host.cmd("exit") {|c| print c }
> }
>
> Which gives me the following... all at once.  Not in 1 second 
> increments as I would have hoped.
>
> ***********************************\/
> started session 192.168.2.54      \/
> ***********************************\/
>
>
> User Access Verification
>
> Username: debug
> Password:
> debug> con t
> config> int m
> config-ifMan> exit
> config> exit
> debug>
> ***********************************/\
> ended session 192.168.2.54       /\
> ***********************************/\
>
> I too figured it was an issue with ruby win32 and sockets, so I tried 
> applying Jean's patch to my cvs version of ruby, but it still waits 
> until I close the socket before printing the output.
>
>> This *could* be an issue with sockets and blocking.  Jean-Francois
>> Nadeau posted a rather large patch for Win32 and sockets, though I
>> don't know whether it will make it into 1.8.2.
>>
>> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/3154
>>
>> I'm not sure if that's the issue or not, though.  As others have
>> suggested, please post some code snippets to help us help you.
>>
>> Regards,
>>
>> Dan
>
>
>
>
  "OS X: because it was easier to make UNIX user-friendly than to fix 
Windows"