net-telnet icon indicating copy to clipboard operation
net-telnet copied to clipboard

Cmd function only accept Prompt for waitfor

Open pommechocolat opened this issue 2 years ago • 0 comments

I deal with a server that never send any prompt. So the cmd can't find any match string. I tried a correction (given here). I suggest to have a cmd option and to be able to send either a Prompt or a Match or a String option to the wait for to avoid the raise of a "tile out while waiting for more data". Is my solution correct ? Could it be possible to include this kind of solution in a next version of this project ?

def cmd(options) # :yield: recvdata
  match = @options["Prompt"]
  time_out = @options["Timeout"]
  fail_eof = @options["FailEOF"] 
  typeMatch = "Prompt"
  if options.kind_of?(Hash)
    cmd   = options["Cmd"] if options.has_key?("String")
    if options.has_key?("String")
      match    = options["String"]
      typeMatch="String"
    end
    if options.has_key?("Match")
      match    = options["Match"]
      typeMatch="Match"
    end
    time_out = options["Timeout"] if options.has_key?("Timeout")
    fail_eof = options["FailEOF"] if options.has_key?("FailEOF")
  else
    cmd = options
  end
  self.puts(cmd)
  if block_given?
    waitfor({typeMatch => match, "Timeout" => time_out, "FailEOF" => fail_eof}){|c| yield c }
  else
    waitfor({typeMatch => match, "Timeout" => time_out, "FailEOF" => fail_eof})
  end
end

pommechocolat avatar Jan 23 '23 12:01 pommechocolat