This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: stdin broken for windows console app under rxvt


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]