Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#50 expect reads input twice

open
nobody
None
5
2008-01-22
2008-01-22
Jens Krinke
No

This script starts bc, sends some input to bc, reads the echo, and then checks the output against the expected output. However, most times expect reads the input twice: For example, after sending "2+2" and reading the echo, the expect that shoud check the output, reads
"2+2" again instead.

I think that the expect versions I tested have an
error, but it might be the case that I have done something wrong.
Here is the script again and some outputs:

spawn bc
sleep 1
proc pass {a} { send_user "PASS $a\n" }
proc fail {a} { send_user "FAIL $a\n" }
proc bc_test {ex result} {
send "$ex\r"
expect "$ex\r\n"
expect {
-gl "$result\r\n" { pass "$ex" }
"*\r\n" { fail "$ex - :$expect_out(buffer):" }
timeout { fail "(timeout) $ex" }
}
}

bc_test "2+2" "4"
bc_test "2+3" "5"
bc_test "2+4" "6"
bc_test "2+5" "7"
bc_test "2+6" "8"

Now, with expect 5.43.0 under SuSE 10.3, the following is output:

% expect -f bc.exp
spawn bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
2+2
2+2
FAIL 2+2 - :2+2
:
4
2+3
5
PASS 2+3
2+4
2+4
FAIL 2+4 - :2+4
:
6
2+5
7
PASS 2+5
2+6
2+6
FAIL 2+6 - :2+6
:

Not quite what I have expected - all should be PASS :-(
The same occurs under MacOS expect 5.42.0 and Debian expect 5.43.0

However, I found one combination that worked:
expect 5.26 under cygwin.

For me it looks like expect is not working correctly in newer versions.

Discussion