X-Spam-Check-By: sourceware.org To: cygwin AT cygwin DOT com From: Eric Blake Subject: Re: freopen irritates system-call/sh.exe Date: Thu, 30 Mar 2006 14:56:54 +0000 (UTC) Lines: 41 Message-ID: References: <442BDED7 DOT 6020107 AT osc-es DOT de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit User-Agent: Loom/3.14 (http://gmane.org/) X-IsSubscribed: yes 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 Note-from-DJ: This may be spam Jens Wilken osc-es.de> writes: > How does freopen-ing stdout and stderr affect subsequent "system" calls? It shouldn't have any effect on subsequent calls, other than that stderr or stdout is mapped to a new underlying stream. There are other changes, unrelated to freopen, that do affect consoles popping up or not (and by the way, snapshot 20060329 flashes a console when cygrunsrv starts an interactive process, which is a regression from snapshot 20060308 - I'll have to narrow it down to when that regression started happening). > > There must have been a change between Cygwin 1.5.10 and 1.5.19, > because the console windows didn't show up in Cygwin 1.5.10. > The freopen manpage states, that the original stream is closed when it > is assigned to the new file. So does freopen try to close the original > console output and what is the effect? Actually, freopen has JUST been patched to support the idiom freopen(NULL, "rb", stdin), available in the 20060329 snapshot or later (it will become part of cygwin 1.5.20). I am planning on releasing an experimental version of tar 1.15.90 that uses this new feature of freopen. And this usage does not close the original console. But in general, if the first argument to freopen is not NULL, then whatever the FILE was using beforehand is closed before assigning the FILE to a new stream (be that a regular file, console, or other device). > > I'm sorry that I can't ask clearer or more specific but I'm really > puzzled by this. It is possible to rewite the code that contains > freopen with dup, dup2 calls but I'd like to understand what happened. Don't bother. I don't think your bug is in freopen. But what you CAN do is test snapshots, and provide feedback as to whether cgf's continual efforts to avoid flashing consoles are making any difference. And if you really do think that freopen is flashing a console, provide a simple test case that we can compile and reproduce the problem. -- Eric Blake -- 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/