We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 810 - Redirecting stdio should be configurable at runtime
Summary: Redirecting stdio should be configurable at runtime
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: main (show other bugs)
Version: HG 1.2
Hardware: x86 Windows (All)
: P2 enhancement
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-26 06:42 UTC by Lauri Kenttä
Modified: 2009-09-26 16:18 UTC (History)
0 users

See Also:


Attachments
Support for disabling stdio redirect with environment variables. (5.68 KB, patch)
2009-09-26 06:42 UTC, Lauri Kenttä
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Lauri Kenttä 2009-09-26 06:42:23 UTC
Created attachment 376 [details]
Support for disabling stdio redirect with environment variables.

Many a programmer finds it annoying that the standard streams stdout and stderr
are by default redirected to the corresponding files, as printf is an important
means of debugging. Altering this behaviour requires basically recompiling the
SDLmain part of the library modifying the build environment to skip WinMain.
Both of these options are difficult for newbies to understand, and while the
second one can probably be done, it would cause the terminal window to become
always visible, which usually is not what the programmer wishes. The
documentation provides some more hacks, namely reopening the files again with
the file name "CON", but this is not a portable solution, as other systems will
take this as a literal file name and produce a file named CON instead of
printing to the console.

I see two possible resolutions.

The redirection could be set explicitly in one of these ways:
SDL_Init(SDL_INIT_STDIO_REDIRECT);
SDL_Init(SDL_INIT_NO_STDIO_REDIRECT);
SDL_EnableRedirect(SDL_REDIRECT_STDOUT | SDL_REDIRECT_STDERR);
SDL_DisableRedirect(SDL_REDIRECT_ALL);

The other option is to use an environment variable:
SDL_NO_STDIO_REDIRECT=1 program.exe
SDL_STDIO_REDIRECT=0 program.exe

I have implemented the latter ones in the attached patch.
Comment 1 Sam Lantinga 2009-09-26 16:18:05 UTC
I've applied your patch, although I'm keeping it to just the one environment variable "SDL_STDIO_REDIRECT"

Thanks!