| delorie.com/archives/browse.cgi | search |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| X-SWARE-Spam-Status: | No, hits=-1.5 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD |
| X-Spam-Check-By: | sourceware.org |
| Message-ID: | <4DCAA510.9000909@sidefx.com> |
| Date: | Wed, 11 May 2011 11:02:40 -0400 |
| From: | Edward Lam <edward AT sidefx DOT com> |
| User-Agent: | Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 |
| MIME-Version: | 1.0 |
| To: | cygwin AT cygwin DOT com |
| Subject: | Re: Who's using "CYGWIN=tty" and why? |
| References: | <20110510211800 DOT CCBDF9D5A21 AT mail2 DOT intersystems DOT com> <20110511063433 DOT GD28594 AT calimero DOT vinschen DOT de> |
| In-Reply-To: | <20110511063433.GD28594@calimero.vinschen.de> |
| 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 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.
Regards,
-Edward
--
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
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |