public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Christopher Faylor <cgf-use-the-mailinglist-please@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: Who's using "CYGWIN=tty" and why?
Date: Wed, 11 May 2011 15:40:00 -0000	[thread overview]
Message-ID: <20110511154025.GC19557@ednor.casa.cgf.cx> (raw)
In-Reply-To: <4DCAA510.9000909@sidefx.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

  reply	other threads:[~2011-05-11 15:40 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-10 21:18 Len Giambrone
2011-05-11  6:35 ` Corinna Vinschen
2011-05-11 10:12   ` David Antliff
2011-05-11 15:02   ` Edward Lam
2011-05-11 15:40     ` Christopher Faylor [this message]
2011-05-11 16:00     ` Edward Lam
2011-05-11 16:00     ` Andy Koppe
  -- strict thread matches above, loose matches on Subject: below --
2011-05-09 16:11 Corinna Vinschen
2011-05-09 16:21 ` Henry S. Thompson
2011-05-09 16:34   ` Corinna Vinschen
2011-05-09 17:37     ` Henry S. Thompson
2011-05-10  8:56       ` Corinna Vinschen
2011-05-10  1:42     ` rifter rifter
2011-05-09 16:32 ` Andrew Schulman
2011-05-09 16:40 ` Edward Lam
2011-05-09 17:03   ` Ken Brown
2011-05-09 20:00   ` Christopher Faylor
2011-05-09 20:06     ` Christopher Faylor
2011-05-09 17:41 ` Lee Maschmeyer
2011-05-09 17:52   ` Samuel Thibault
2011-05-09 20:05     ` Christopher Faylor
2011-05-09 20:23       ` Samuel Thibault
2011-05-10 14:09         ` Corinna Vinschen
2011-05-10 14:59           ` Andy Koppe
2011-05-10 13:39       ` Lee Maschmeyer
2011-05-10 15:36         ` Charles Wilson
2011-05-10 16:45         ` Lee Maschmeyer
2011-05-09 21:14 ` Karl M
2011-05-09 21:39   ` Jeremy Bopp
2011-05-09 22:27 ` Thomas Wolff
2011-05-09 23:18   ` Christopher Faylor
2011-05-10  2:30 ` Claude Sylvain
2011-05-10  8:29 ` Csaba Raduly
2011-05-10  9:02   ` Corinna Vinschen
2011-05-10 13:38 ` Buchbinder, Barry (NIH/NIAID) [E]
2011-05-10 17:19   ` Christopher Faylor
2011-05-10 17:50     ` Christopher Faylor
2011-05-10 22:12     ` Buchbinder, Barry (NIH/NIAID) [E]
2011-05-10 22:17       ` Christopher Faylor
2011-05-10 14:51 ` Bernhard Ege
2011-05-10 14:58   ` Jeremy Bopp
2011-06-08 19:30 ` Christopher Faylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110511154025.GC19557@ednor.casa.cgf.cx \
    --to=cgf-use-the-mailinglist-please@cygwin.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).