delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/03/12/20:11:45

X-Spam-Check-By: sourceware.org
Message-ID: <4414C6C1.F13AC10B@dessent.net>
Date: Sun, 12 Mar 2006 17:11:29 -0800
From: Brian Dessent <brian AT dessent DOT net>
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: stdin broken for windows console app under rxvt
References: <A521CED2010C244BBDC949DEDF00DCE23645F0 AT sydexchange2 DOT vignette DOT com>
X-IsSubscribed: yes
Reply-To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
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

"Robinson, Mark" wrote:

> A simple console app compiled with MingW (-mno-cygwin) (or VC++) cannot
> read from stdin when executed in an rxvt or xterm terminal:
> 
> #include <stdio.h>
> main() {
>   int c;
>   fputc(isatty(stdin), stdout);
>   while ((c = getc(stdin)) != EOF) fputc(c, stdout);
> }
> 
> Furthermore, isatty(stdin) returns 0.
> 
> Both examples behave under cmd, or cmd/bash with CYGWIN=notty set, or if
> they're compiled without the mingw flag.

Yes.  This is the expected behavior.

First of all, when you use -mno-cygwin are you no longer using Cygwin,
you are using mingw which uses the Microsoft C library (MSVCRT.DLL). 
So, your question belongs on a mingw mailing list, not here.

When you run a program in Cygwin's rxvt, or with $CYGWIN=tty under a
normal windows bash console, it will use pty emulation.  The key word
here is emulation -- the application has to be a Cygwin app to
participate in this fiction because ptys don't exist on Windows.  So to
a mingw program attached to a pty there is no console, and stdin/stdout
are pipes.  Thus isatty() returns false, and interactive IO will be
cumbersome because MSVCRT buffers the IO since it's not attached to a
console.  You can improve the chances of things working by manually
disabling buffering on stdin/stdout.  But I doubt you'll ever get
isatty() to return true when the app is run attached to a pty.

In the normal windows bash console with $CYGWIN empty or set to notty
(which is the default, so setting it to notty is a no-op), a pty is not
used, and the app's IO is actually attached to the windows console, so
everything works as expected.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019