How can I get console output instead of stdout.txt and stderr.txt?
SDL_Init() routes stdout and stderr to the respective files. You can revert this by adding the following lines after the call to SDL_Init in your code:
freopen( "CON", "w", stdout ); freopen( "CON", "w", stderr );
If that doesn't work try adding these 2 lines at the very beginning of your code (SDL_Init wrapper or in top of your main)
- if THAT doesn't work, try the following:
#include <fstream> #include <iostream> using namespace std; .... ofstream ctt("CON"); freopen( "CON", "w", stdout ); freopen( "CON", "w", stderr ); ... ctt.close();
FILE * ctt = fopen("CON", "w" ); freopen( "CON", "w", stdout ); freopen( "CON", "w", stderr ); ... ctt.close();
These options may work better since "freopen" implies that the "file" (in this case, the console) is already open and it may not be.
For those of you using Visual Studio .NET (probably works with VC6 too), in project properties be sure to set linker->subsystem to CONSOLE, or your project won't be allowed to trigger a console even if you've done everything correctly.
If that doesn't work, another option is to recompile libSDLmain.a. The easiest way to do so is by using MinGW and MSYS:
Download the SDL source code SDL-1.2.9.zip, and unpack it into C:\
- * to use MSYS with MinGW do ( assuming MinGW is on c:\mingw) :
mount c:/mingw /mingw
- * Open MSYS ( msys.bat )
- * do the following:
$ cd /c/SDL-1.2.9 $ ./configure --disable-stdio-redirect $ cd src/main $ make
There should now be a new libSDLmain.a in C:\SDL-1.2.9\src\main. Copy that file to the appropriate location for your compiler/linker. If you're using MinGW that will probably be C:\MinGW\lib.
Recompile your program. Be sure that you don't pass -mwindows to the compiler, or things still won't work!
Another option is to include SDL-1.2.9\src\main\win32\SDL_win32_main.c from the SDL source in your project and then not link with libSDLmain.a at all. When you compile your program, be sure to pass -DNO_STDIO_REDIRECT to the compiler. Once again, also be sure that you don't pass -mwindows to the compiler.