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

2011-09-16 Thread Eric Blake

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 bo\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 bo\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   ebl...@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



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

2011-09-16 Thread Oleksandr Gavenko

This script work fine:

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

set stty_init "sane cooked -echo"

spawn sort
send \x04
expect eof
wait


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

  send bo\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 bo\x03

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


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