delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/05/11/11:40:50

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY
X-Spam-Check-By: sourceware.org
X-Yahoo-SMTP: jenXL62swBAWhMTL3wnej93oaS0ClBQOAKs8jbEbx_o-
Date: Wed, 11 May 2011 11:40:25 -0400
From: Christopher Faylor <cgf-use-the-mailinglist-please AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Who's using "CYGWIN=tty" and why?
Message-ID: <20110511154025.GC19557@ednor.casa.cgf.cx>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <20110510211800 DOT CCBDF9D5A21 AT mail2 DOT intersystems DOT com> <20110511063433 DOT GD28594 AT calimero DOT vinschen DOT de> <4DCAA510 DOT 9000909 AT sidefx DOT com>
MIME-Version: 1.0
In-Reply-To: <4DCAA510.9000909@sidefx.com>
User-Agent: Mutt/1.5.20 (2009-06-14)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT 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 Wed, May 11, 2011 at 11:02:40AM -0400, Edward Lam wrote:
>On 5/11/2011 2:34 AM, Corinna Vinschen wrote:
>> Kind of weird.  The difference is that in tty mode the stdio handles are
>> pipes, while in the notty case the stdio handles are console handles.
>> Usually native Windows applications shouldn't see a difference and even
>> work *better* in notty mode.
>
>One problem I ran into was with *Windows mode* applications (ie. MS 
>link.exe option /SUBSYSTEM:windows) trying to detect stdout redirection. 
>I apologize that this takes a bit of explaining first as to why we run 
>into a problem with Cygwin.
>
>For Windows-mode applications, _isatty(_fileno(stdout)) will always 
>return false. Due to a bug (in Windows and/or the CRT), the FILE *stdout 
>object will be initialized to a black hole. So if you want printf's to 
>make its way into the redirected file, you have to manually connect the 
>FILE *stdout object to the redirected file output handle.
>
>The usual method is to call GetStartupInfo(&info) and check if 
>info.dwFlags has the STARTF_USESTDHANDLES flag set. If it is set, then 
>assume that info.hStdOutput contains the redirected file output handle 
>and attach it with something like:
>    *stdout = _fdopen(_open_osfhandle(info.hStdOutput, _O_TEXT));
>
>So this brings us to Cygwin. When we spawn such a Windows mode app from 
>Cygwin, the method I describe above fails. The call to 
>_open_osfhandle(info.hStdOutput, _O_TEXT) returns with an error value of 
>-1. This is likely why jam reports "the handle is invalid".
>
>Personally, when I first ran into this problem, I never realized that 
>CYGWIN=tty would fix it. I did notice that there was a change in the 
>behavior between Cygwin B20 and the Cygwin 1.X releases but I only 
>realize now that this was probably the reason.

Just to go on mean record: I don't think the fact that jam works better
as side effect of setting CYGWIN=tty is a good enough reason to derail
any plans to get rid of CYGWIN=tty.

It seems like you might be able to get the same behavior by saying

jam </dev/null 2>&1 | cat

cgf

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