Thanks Brian!
The problem is that "I might have two possible prompts in response to
one command"
When I execute the command "go" on Telnet, I can either get the:
prompt 1: BDI> (or)
prompt 2: - TARGET: stopped \n BDI>
When I get prompt 1, I want it to send in the instructions:
"re"
"ci"
"bi 0x000044bc"
"go 0"
However when i get prompt 2, i want to send in the instructions:
"dump 0x003f7670 128 C:/Dump/atl.dat"
"go".
Based on ur suggestion I modified the code to (also attached):
-------------------------------------
class RBDI_test
attr_accessor :quiet
def initialize(options)
@prompt = /- TARGET: stopped \n BDI>|BDI>/
@quiet = options['Quiet']
@quiet = true if @quiet.nil?
@connection = Net::Telnet.new({'Host' => options['Host'],
'Prompt' => @prompt}) {|str| print
str unless @quiet}
# consume the initial display of help
@connection.waitfor(@prompt) {|str| print str unless @quiet}
end
# Send a script of commands to the BDI
# If script is a filename, the commands will be read from the file.
# The Quiet option specified at creating may be overruled for this
script.
def send(script, options={'Quiet' => @quiet})
script = File.new(script) if FileTest.file? script
begin
script.each_line do |command|
@connection.cmd(command.strip) do |str|
print str unless str.nil? or options['Quiet']
end
end
rescue Errno::ECONNRESET, Errno::ECONNABORTED
puts "Connection closed" unless options['Quiet']
return
end
end
end
------------------------
AND
----------
require 'rbdi_test'
bdi = RBDI_test.new({'Host' => 'bdiemul'})
bdi.quiet = false
bdi.send("Prompt"=>/BDI>/) <<-LOAD_SCRIPT
re
ci
bi 0x000044bc
go 0
LOAD_SCRIPT
j = true
while j
bdi.send("Prompt"=>/- TARGET: stopped \n BDI>/) <<-LOAD_SCRIPT
dump 0x003f7670 128 C

ump/atl.dat
go
LOAD_SCRIPT
end
sleep 1
-------------------------
I end up with the error:
C:/load565-released/test.rb:18: syntax error, unexpected tINTEGER,
expecting kEND
dump 0x003f7670 128 C

ump/atl.dat
Amogh.
^
Attachments:
http://www.ruby-forum.com/attachment/3903/test.zip