Subject: Re: bug#12908: 24.3.50; file `emacs_backtrace.txt'?

From: Eli Zaretskii <[email-masked]>
Date: Sun, 18 Nov 2012 06:04:28 +0200

> Date: Sat, 17 Nov 2012 13:25:17 -0800
> From: Paul Eggert <[email-masked]>
> CC: [email-masked]
> 
> >> Perhaps it would be better for Emacs, on Microsoft Windows, to
> >> redirect stderr to a file, so that the information does not get
> >> lost.
> > 
> > It's not easy to do that
> 
> Can Emacs use freopen?

That's not the problem.  The problem is that stderr is used when Emacs
is run in non-interactive mode, and should not be touched then.  The
problem is in detecting when stderr is closed or an invalid handle to
begin with, and do the redirection only then.  In all my readings and
tests, I was unable to find a reliable, let alone documented, way of
determining that.  I don't even know if the "invalid handle" (which is
a pointer on Windows) is NULL or an INVALID_HANDLE_VALUE.

> For example, the following code would do the job on a POSIX
> platform: if stderr is closed, it redirects it to emacs-stderr.txt
> in the current directory, if possible.  Would this sort of thing
> work on Microsoft platform?

It will surely break -batch.  And guess what happens with this
redirection when Emacs has its stderr closed or invalid in the first
place.