X-Spam-Check-By: sourceware.org Message-ID: <4414C6C1.F13AC10B@dessent.net> Date: Sun, 12 Mar 2006 17:11:29 -0800 From: Brian Dessent MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: stdin broken for windows console app under rxvt References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Reply-To: cygwin AT cygwin DOT com Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , 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 > 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/