I have been unable to get Expect to recognize and respond appropriately to early end-of-file or to timeout. This occurs in console terminals as well as various X windows. I have short sample code. Reproducible: Always Steps to Reproduce: 1.Put script.exp and count.sh in the current directory. 2.Make count.sh executable; set the timeout number to -1 or some positive integer (seconds). 3.enter "expect script.exp" Actual Results: It shows output from count.sh then "Normal end" Expected Results: Since the script is expecting the word "four", it should either time out (if the timeout is not set to -1), or an early EOF from the program. It does neither. This is also happening in my Ubuntu version, so I think this may be widespread.
Created attachment 257072 [details] A bash script that counts to three
Created attachment 257073 [details] An expect script that should wait for a "four"
It turns out that a minor change to the text of script.exp makes this work again. I can find no documentation in the Expect manual of why this might be so, but adding a newline and whitespace to change expect { -exact "four\r" { exit 1; } timeout { send_user "\ntimeout\n"; exit 2; } eof { send_user "\nEarly end\n"; exit 3; } } to expect { -exact "four\r" { exit 1; } timeout { send_user "\ntimeout\n"; exit 2; } eof { send_user "\nEarly end\n"; exit 3; } } makes the timeout and eof capabilities work as "expected". I know of no rule that explains this, but I have a workaround.
seems to work for me: $ expect -v expect version 5.44.1.15 $ ./script.exp spawn ./count.sh one two three Normal end
(In reply to comment #4) > seems to work for me: > $ expect -v > expect version 5.44.1.15 > $ ./script.exp > spawn ./count.sh > one > two > three > Normal end That's really odd. I only found the cause because a friend using a different distro hand-entered the expect code, and didn't find the problem at first. He found it when he examined closely and realized he'd rearranged the whitespace. I then found that the same rearrangement made the problem go away on my system. I'm seeing the same thing in Ubuntu Lucid and Fedora Core 11, so I've assumed this is an upstream generic problem. A long shot: What's your machine architecture? I'm running x86 32-bit all the way.
(In reply to comment #5) > (In reply to comment #4) > > seems to work for me: > > $ expect -v > > expect version 5.44.1.15 > > $ ./script.exp > > spawn ./count.sh > > one > > two > > three > > Normal end > > That's really odd. I only found the cause because a friend using a different > distro hand-entered the expect code, and didn't find the problem at first. He > found it when he examined closely and realized he'd rearranged the whitespace. > I then found that the same rearrangement made the problem go away on my system. > > I'm seeing the same thing in Ubuntu Lucid and Fedora Core 11, so I've assumed > this is an upstream generic problem. > > A long shot: What's your machine architecture? I'm running x86 32-bit all the > way. > Oops, correction: That was Fedora Core 9 I used to verify the issue. And I've just done the same on CentOS 5.2 (Final) I'm attaching a script1.exp and script2.exp which are the two variants with unexplained differences in results.
Created attachment 257505 [details] Script that recognizes eof and timeout as documented
Created attachment 257506 [details] Script that fails to recognize eof or timeout, but I don't know why.
you could try expect-5.45, but if that fails too and on other distros, then best place probably is sf.net/projects/expect ...