Help me understand why 'eof' in canonical mode works strange in Expect script (and differ from Linux).

Oleksandr Gavenko
Fri Sep 16 21:44:00 GMT 2011

This script work fine:

   $ cat eof.exp
#!/usr/bin/env expect

set stty_init "sane cooked -echo"

spawn sort
send \x04
expect eof

But if I modify send expression to any like (so ^D is last char):

   send booooo\x04

script infinitely await closing stdout by "sort", but
sort itself wait for closing stdin, which not happen.

Look like \x04 have 'eof' meaning in Expect pty only
in case then spawned process stdin empty.

For example this is not work ("sort" don't get 'eof'):

   spawn sort
   send bbb\raaa\r\0x04
   expect -re .+ { send_user $expect_out(buffer); exp_continue } eof { }

But this script work fine (but it is have drawback in 1 sec delay
before "sort" get 'eof'...):

   spawn sort
   send bbb\raaa\r
   set timeout 1
   expect {
     -re .+ { send_user $expect_out(buffer); exp_continue }
     timeout { send \x04; exp_continue }
     eof { }

I try Linux and surprised that all my Expect scripts work fine.
Also note that sending another special character seems work in

   send booooo\x03

pattern (on INTR  with "booo\x03" "sort" exit,
on QUIT with "booo\x1c" "sort" exit and 'sort.exe.stackdump' created).

Problem reports:
Unsubscribe info:

More information about the Cygwin mailing list