| Summary: | Redirecting stdio should be configurable at runtime | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Lauri Kenttä <lauri.kentta> |
| Component: | main | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | enhancement | ||
| Priority: | P2 | ||
| Version: | HG 1.2 | ||
| Hardware: | x86 | ||
| OS: | Windows (All) | ||
| Attachments: | Support for disabling stdio redirect with environment variables. | ||
I've applied your patch, although I'm keeping it to just the one environment variable "SDL_STDIO_REDIRECT" Thanks! |
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.