From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3076 invoked by alias); 4 Jan 2009 19:29:04 -0000 Received: (qmail 3066 invoked by uid 22791); 4 Jan 2009 19:29:03 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from nf-out-0910.google.com (HELO nf-out-0910.google.com) (64.233.182.188) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 04 Jan 2009 19:28:59 +0000 Received: by nf-out-0910.google.com with SMTP id b11so985629nfh.18 for ; Sun, 04 Jan 2009 11:28:55 -0800 (PST) Received: by 10.210.35.10 with SMTP id i10mr11524872ebi.86.1231097335343; Sun, 04 Jan 2009 11:28:55 -0800 (PST) Received: by 10.210.92.6 with HTTP; Sun, 4 Jan 2009 11:28:55 -0800 (PST) Message-ID: <2ca21dcc0901041128p575daca2xefee07e52e10c147@mail.gmail.com> Date: Sun, 04 Jan 2009 21:30:00 -0000 From: "Dave Korn" To: cygwin@cygwin.com Subject: Re: printf goes to serial port? In-Reply-To: <4960ED6A.7030303@xs4all.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <4960ED6A.7030303@xs4all.nl> Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2009-01/txt/msg00081.txt.bz2 Bob van Loosen wrote: > Because of this, the app doesn't get the standard file descriptors for > stdin, stdout and stderr, also when you open a file the file descriptors > start at 0. > > So what happens is, my app opens a config file, which then becomes > stdin, then it opens a serial port, which becomes stdout, causing all > printf statements to go out the serial port. > The solution is quite simple, just disable all printf statements for a > cygwin build. Well... that requires editing every single printf in the whole program, no? It might be easier to just at the start of main() open the first three file descriptors, so that 0, 1 and 2 are allocated. If you open 0 from /dev/null in read mode and open 1 and 2 for write to /dev/null, all your stdio should behave sensibly. Then if you decide you want the printfs after all, you can just change the open to point to a real file and bingo! Instant log file! > I have no idea how to get console output when using the > -mwindows flag, but I don't really need it. You probably need to call AllocConsole and open stdio channels to CONIN$/CONOUT$, but that's off the top of my head and without looking it up. cheers, DaveK -- 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/