Project

General

Profile

Actions

Feature #1473

closed

Improvements on expect.rb

Added by luizluca (Luiz Angelo Daros de Luca) almost 15 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
[ruby-core:23464]

Description

=begin
Hello,

I was using expect.rb to substitute expect command (as I'm not in a mood to learn Tcl). However, it demands some attention.

I took expect(1) command as a idea, but not a rule, of how expect should behave.

First, a little bug that incorrect pattern classes are not treated correctly. It would result in a "e_pat unspecified" which gives no clues of what happened. Now I raise an exception. I let the another one parameter, timeout, unchecked cause the error messagem like "String can't be coerced into Fixnum" would give a good hint of what is wrong.

I changed pat and e_pat to pattern to meet some other similar parameter references.

Back to the timeout parameter, timeout was not a global timeout but a single char timeout. If the io keeps giving input, it never stops. For example: While using expect.rb to interact with a dlink switch telnet, if it generates any log information on the terminal (as it does constantly like "link down") before the timeout time, even if my expression never occurs, the timeout is never over. I changed this to use timeout as a global timeout as expect command does.

Keeping on timeout stuff, if it read some input and times out, where this buffer goes? In expect.rb, it is just lost. For the expect command, this buffer can be used in the next matching. I use a instance variable to keep and reuse the unused buffer on the next expect call.

I changed the default timeout value to meet the expect command default one. If someone really wants to use 9999999 seconds, just go ahead ans specify it on parameters. However, interactive scripts generally deal with unexpected behaviors. 30s, as expect command uses, seems to be reasonable.

I also added some documentation that was missing.
=end


Files

expect.patch (1.77 KB) expect.patch luizluca (Luiz Angelo Daros de Luca), 05/16/2009 02:55 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0