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 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: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , 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