X-Recipient: archive-cygwin@delorie.com
X-SWARE-Spam-Status: No, hits=-5.3 required=5.0	tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
In-Reply-To: <4FE23FDE.9070506@redhat.com>
References: <4FE1FB4F.3020808@kempt.net>	<4FE1FD33.3070009@redhat.com>	<4FE23EB0.2020406@kempt.net>	<4FE23FDE.9070506@redhat.com>
Date: Thu, 21 Jun 2012 07:34:52 -0400
Message-ID: <CA+sc5mkiNQXi-6nXwjQAR2qBnKLhBOScOAqQYMp1RA1Ay9Xyhg@mail.gmail.com>
Subject: Re: piping input to executable reading from /dev/tty?
From: Earnie Boyd <earnie@users.sourceforge.net>
To: cygwin@cygwin.com
Content-Type: text/plain; charset=UTF-8
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
Precedence: bulk
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie.com@cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id q5LBZDbW030931

On Wed, Jun 20, 2012 at 5:25 PM, Eric Blake wrote:
> On 06/20/2012 03:20 PM, Dan B. wrote:
>> Eric Blake wrote:
>>> On 06/20/2012 10:33 AM, Dan B. wrote:
>>>> Is there any way to redirect /dev/tty similarly to how stdin can be
>>>> redirected (e.g., like "echo ... | someexecutable")?
>>>
>>> Yes; use 'expect'.
>>>
>>>> Does Cygwin (or Unix/Linux, for that matter) have any equivalent way
>>>> of redirecting /dev/tty?
>>>>
>>>> Can /dev/tty be redirected at all?  (I would guess that something
>>>> could be done with pseudoterminals, but I know very little about
>>>> them.)
>>>
>>> Yes, 'expect' is the command line tool that lets you script around
>>> programs that expect to be run interactively, but where you want to
>>> script the input that your program will see.
>>
>> Does expect use only redirection of file descriptors, or can it also
>> redirect references to /dev/tty?
>
> expect uses pseudoterminals so that the stdin of the child process is
> also its /dev/tty (remember, /dev/tty is a magic name that resolves to
> the current controlling terminal, and that a pseutoterminal can be a
> controlling terminal).  Therefore, anything that normally requires you
> to interactively type something because the child process opened
> /dev/tty can be run under expect, where opening /dev/tty in the child
> will now be asking expect for the input, and expect then hands it the
> information that you wrote into your expect script.  This is not
> cygwin-specific, so you may get better support by looking for help on
> using 'expect'.

A word of caution, do not expect expect to function properly to a
native (non-Cygwin) process. The PTY emulation cannot support it.

-- 
Earnie
-- https://sites.google.com/site/earnieboyd

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


