delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/09/16/17:44:22

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL,BAYES_05,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS
X-Spam-Check-By: sourceware.org
Message-ID: <4E73C315.5080607@redhat.com>
Date: Fri, 16 Sep 2011 15:43:49 -0600
From: Eric Blake <eblake AT redhat DOT com>
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.20) Gecko/20110831 Fedora/3.1.12-2.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.12
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Help me understand why 'eof' in canonical mode works strange in Expect script (and differ from Linux).
References: <j50f1v$uli$1 AT dough DOT gmane DOT org>
In-Reply-To: <j50f1v$uli$1@dough.gmane.org>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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 AT redhat DOT 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019