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: freopen irritates system-call/sh.exe

Jens Wilken <Jens.Wilken <at>> 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:
Problem reports:

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