delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT com |
X-SWARE-Spam-Status: | No, hits=-2.2 required=5.0 tests=AWL,BAYES_00 |
X-Spam-Check-By: | sourceware.org |
Message-ID: | <49611D65.8010808@xs4all.nl> |
Date: | Sun, 04 Jan 2009 21:34:45 +0100 |
From: | Bob van Loosen <loosen AT xs4all DOT nl> |
User-Agent: | Thunderbird 2.0.0.18 (X11/20081125) |
MIME-Version: | 1.0 |
To: | cygwin AT cygwin DOT com |
Subject: | Re: printf goes to serial port? |
References: | <4960ED6A DOT 7030303 AT xs4all DOT nl> <2ca21dcc0901041128p575daca2xefee07e52e10c147 AT mail DOT gmail DOT com> |
In-Reply-To: | <2ca21dcc0901041128p575daca2xefee07e52e10c147@mail.gmail.com> |
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 |
Dave Korn wrote: > 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! > Here's an even better solution: stdin = fopen("/dev/null", "r"); stdout = fopen("/dev/null", "w"); stderr = fopen("/dev/null", "w"); And then use fprintf on the respective file pointer, this ensures that any output will go to /dev/null, even if the file descriptors don't start at 0, which can happen (think library constructors). Bob. -- 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/
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |