Getting rid of stdout redirect

By default, SDLmain redirects stdout and stderr to files. This is a
configure-time option in the static portion of the library. For my
program, this is blatantly wrong behavior and not acceptable (dedicated
server using SDL that’s expected to be interactive on stdin/stdout).
Now, I can recompile SDL to not do this, but…

I can’t really tell someone who downloads a source tarball that they
need to recompile SDL with a nonstandard option, and I certainly
can’t make a configure check for it. My present workaround is to
compile SDL_win32_main.c directly into the project with
NO_STDIO_REDIRECT defined, but that’s clearly an ugly hack/bad idea.

Is there any way to cleanly work around this? Better behavior would
be for SDL to wait until sdlInit is called, and provide an option to
control whether stdio should be redirected. Or best of all, just drop
the redirection thing entirely and provide a library function for it.–
CalcRogue: TI-89, TI-92+, PalmOS, Windows and Linux.
http://calcrogue.jimrandomh.org/

jimrandomh wrote:

By default, SDLmain redirects stdout and stderr to files. This is a
configure-time option in the static portion of the library. For my
program, this is blatantly wrong behavior and not acceptable (dedicated
server using SDL that’s expected to be interactive on stdin/stdout).
Now, I can recompile SDL to not do this, but…

I can’t really tell someone who downloads a source tarball that they
need to recompile SDL with a nonstandard option, and I certainly
can’t make a configure check for it. My present workaround is to
compile SDL_win32_main.c directly into the project with
NO_STDIO_REDIRECT defined, but that’s clearly an ugly hack/bad idea.

Is there any way to cleanly work around this? Better behavior would
be for SDL to wait until sdlInit is called, and provide an option to
control whether stdio should be redirected. Or best of all, just drop
the redirection thing entirely and provide a library function for it.

From what little I can find on the semantics of freopen (the method
used to do the redirection) there’s no general application level manner
of undoing these redirects. I’d check the site/CVS for possible
environment variables to override this (not sure if there are any) but
libsdl.org appears down (Too many clients PostgreSQL error message ~_~)
and I don’t have the direct links on me, nor source.

jimrandomh wrote:

By default, SDLmain redirects stdout and stderr to files. This is a
configure-time option in the static portion of the library. For my
program, this is blatantly wrong behavior and not acceptable (dedicated
server using SDL that’s expected to be interactive on stdin/stdout).
Now, I can recompile SDL to not do this, but…

I can’t really tell someone who downloads a source tarball that they
need to recompile SDL with a nonstandard option, and I certainly
can’t make a configure check for it. My present workaround is to
compile SDL_win32_main.c directly into the project with
NO_STDIO_REDIRECT defined, but that’s clearly an ugly hack/bad idea.

Is there any way to cleanly work around this? Better behavior would
be for SDL to wait until sdlInit is called, and provide an option to
control whether stdio should be redirected. Or best of all, just drop
the redirection thing entirely and provide a library function for it.

Have you tried switching to a CONSOLE project? I believe that should
shut off the redirection.

“Philip D. Bober” wrote:

jimrandomh wrote:

By default, SDLmain redirects stdout and stderr to files. This is
a configure-time option in the static portion of the library. For
my program, this is blatantly wrong behavior and not acceptable
(dedicated server using SDL that’s expected to be interactive on
stdin/stdout). Now, I can recompile SDL to not do this, but…

I can’t really tell someone who downloads a source tarball that
they need to recompile SDL with a nonstandard option, and I
certainly can’t make a configure check for it. My present
workaround is to compile SDL_win32_main.c directly into the
project with NO_STDIO_REDIRECT defined, but that’s clearly an
ugly hack/bad idea.

Is there any way to cleanly work around this? Better behavior
would be for SDL to wait until sdlInit is called, and provide an
option to control whether stdio should be redirected. Or best of
all, just drop the redirection thing entirely and provide a
library function for it.

Have you tried switching to a CONSOLE project? I believe that
should shut off the redirection.

I’m not using Visual C, I’m using MinGW. And the MinGW equivalent of a
console project (using main() as the insertion point) doesn’t work if
SDL is linked in. Besides, telling VC to use a console project has
other side-effects (like spawning a console window even if you don’t
want one).–
CalcRogue: TI-89, TI-92+, PalmOS, Windows and Linux.
http://calcrogue.jimrandomh.org/