Possible expect bug: interact closes stdout



I'm running into an issue in which expect (5.42.1 and 5.43.0) closes stdout
if a script that uses the interact statment is run with input redirected
from /dev/null. It seems like a bug to me, since I don't see why stdout
should be affected. Here's the script:

---- 8< ---------------------------------------------------------
#!/usr/bin/expect

proc bugaboo { count } {
puts -nonewline "Here's some initial output (count=$count)\n"
spawn date
expect 2007
interact
puts -nonewline "============================================\n"
wait -nowait
}

set count 0
while true {
incr count
if { [catch { bugaboo $count } error] } {
send_error "An error occurred (count=$count): '$error'\n"
catch { send_user "This will produce no output\n" }
catch { puts "And neither will this" }
exit $count
}
}
---- 8< ---------------------------------------------------------

If you run this script with no input redirection it will loop indefinitely,
as expected. If you run it with "< /dev/null", though, it will bomb with
'error writing "stdout": bad file number' on either the first or second
iteration, and both the send_user and puts statements within the if will
produce no output:

---- 8< ---------------------------------------------------------
% ./script < /dev/null
Here's some initial output (count=1)
spawn date
Fri Nov 30 10:53:32 PST 2007
============================================
Here's some initial output (count=2)
spawn date
Fri Nov 30 10:53:33 PST 2007
An error occurred (count=2): 'error writing "stdout": bad file number'
---- 8< ---------------------------------------------------------

If you comment out the "expect 2007" it always bombs on the first loop.

Removing the interact statement fixes the problem, so the interact is
definitely the source of this behavior. I'd have thought that using
interact in a script with input redirected from /dev/null would just
behave like an expect statement, but that's not what's happening.

Is this a bug? If not, can anyone explain what's going on here?

- John
.



Relevant Pages

  • Re: Using sendkeys in a web form
    ... to interact with the GUI interface - unless you are a script. ... know where to navigate to, is MUCH harder than finding it in the raw HTML ...
    (microsoft.public.scripting.vbscript)
  • Re: [Expect] Need to have explanations for the use of the expectcommand
    ... Otherwise I think the script is OK. ... spawn ssh root@remtest1 cd logs; ... you will be able to interact with your test setup. ... I put the interact command at the end (in place of the ...
    (comp.lang.tcl)
  • Expect: interact and buffering?
    ... with the tcl application and terminated it. ... remaining output would display and the Expect script would end. ... I have changed the interact in an attempt to make it process character ...
    (comp.lang.tcl)
  • Exepect, curses, and screen control
    ... I have a script I am working on that uses the Perl expect module. ... It lets the user interact with the ... then when the user hits a control key - it leaves the ...
    (comp.lang.perl.misc)
  • Need help - expect script: Copy a file from tftp server to cisco router flash
    ... I have following script that fails on one of the interactive prompt. ... pretty much took it from the working autoexpect and made it prettier but ... set timeout -1 ... at interact it simply doesn't work on my response. ...
    (comp.lang.tcl)