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

Eric Blake eblake@redhat.com
Sat Sep 17 03:53:00 GMT 2011


On 09/16/2011 03:28 PM, Oleksandr Gavenko wrote:
> This script work fine:
> 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.

This is not cygwin-specific.  On a tty, ^D (\x04) means to flush the 
current input buffer (well, ^D is default, but you can use stty to 
change which input sequence has that effect - some people like ^Z to 
match Windows).  If there is no input, then flushing results in read() 
of the tty returning 0, which the reader interprets as EOF.  But if 
there is input, the flushing results in read() of the tty returning that 
input.

Basically, ^D is _not_ EOF, but flush - if there is no data, it has the 
same effect as EOF, but if there IS data, then you need a double ^D to 
get to EOF (one to flush the data, the next to flush an empty line).

> For example this is not work ("sort" don't get 'eof'):
>
> spawn sort
> send bbb\raaa\r\0x04

You want to use \n, not \r, to give end of line to sort.

>
> 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

That sends ^C, which maps to the interrupt line (again, something that 
stty can change if you don't like the default), and most apps know to 
quit as fast as possible on receipt of SIGINT.

Seeing as how your questions are not cygwin specific, you may want to 
spend more time googling about how Unix ttys behave.

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list