[SDL2]-Output SDL Info To Text File In EXE Folder?

[SDL2]-Output SDL Info To Text File In EXE Folder?

Hi,

Old SDL 1.2 allowed output to “stdout” and “stderr” text files in EXE’s folder.
New SDL 2.0 does not allow this.
How can I output SDL2 info into a text file in the EXE’s folder on Windows®?

Thanks!

I tried this code, but no “stderr” or “stdout” files are found in the EXE folder?:

Code:
if ( SDL_Init(SDL_INIT_EVERYTHING) != 0 )
{
fprintf( stderr, “Unable to initialize SDL: %s\n”, SDL_GetError() );
return(1);
}
else fprintf(stdout, “SDL initialized.\n”);------------------------
JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft®
Video Game Design Studio
www.16BitSoft.com

You don’t really want it. Especially given that’d mean it’d end up
writing in Program Files when the program is installed, which requires
admin privileges. Open a console if you need to see the logs.

If you really want to do it, you may want to give a try to freopen
(using “CON” as the new filename). I’m not sure if it works though.

2013/8/26, JeZ-l-Lee :> [SDL2]-Output SDL Info To Text File In EXE Folder?

Hi,

Old SDL 1.2 allowed output to “stdout” and “stderr” text files in EXE’s
folder.
New SDL 2.0 does not allow this.
How can I output SDL2 info into a text file in the EXE’s folder on
Windows®?

Thanks!

I tried this code, but no “stderr” or “stdout” files are found in the EXE
folder?:

Code:
if ( SDL_Init(SDL_INIT_EVERYTHING) != 0 )
{
fprintf( stderr, “Unable to initialize SDL: %s\n”, SDL_GetError() );
return(1);
}
else fprintf(stdout, “SDL initialized.\n”);


JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft®
Video Game Design Studio
www.16BitSoft.com

Er, using the new filename, not “CON” (that restores the old behavior). Whoops.

2013/8/26, Sik the hedgehog <@Sik_the_hedgehog>:> You don’t really want it. Especially given that’d mean it’d end up

writing in Program Files when the program is installed, which requires
admin privileges. Open a console if you need to see the logs.

If you really want to do it, you may want to give a try to freopen
(using “CON” as the new filename). I’m not sure if it works though.

2013/8/26, JeZ-l-Lee :

[SDL2]-Output SDL Info To Text File In EXE Folder?

Hi,

Old SDL 1.2 allowed output to “stdout” and “stderr” text files in EXE’s
folder.
New SDL 2.0 does not allow this.
How can I output SDL2 info into a text file in the EXE’s folder on
Windows®?

Thanks!

I tried this code, but no “stderr” or “stdout” files are found in the EXE
folder?:

Code:
if ( SDL_Init(SDL_INIT_EVERYTHING) != 0 )
{
fprintf( stderr, “Unable to initialize SDL: %s\n”, SDL_GetError() );
return(1);
}
else fprintf(stdout, “SDL initialized.\n”);


JeZ+Lee
JessePalser <AT> Gmail <DOT> com
16BitSoft®
Video Game Design Studio
www.16BitSoft.com

Sik wrote:

You don’t really want it. Especially given that’d mean it’d end up
writing in Program Files when the program is installed, which requires
admin privileges. Open a console if you need to see the logs.

This.

Sik wrote:

If you really want to do it, you may want to give a try to freopen
(using “CON” as the new filename). I’m not sure if it works though.

This will work if you have permission for the current directory. I’ve created the files in a directory in the user’s folder to get around the Program Files problem, and letting the game’s help dialog explain where to find them.
Another option is to simply not use stderr/stdout, and instead use a file created with fopen. (semantically, freopen(f, fname, mode) is just fclose(f); f=fopen(fname, mode) anyway)------------------------
Nate Fries

Assuming you’re creating a program for a normal end-user, and not a computer-savvy person like most of us on here, what you really want to do in the case of a show-stopping error is to alert the user and exit gracefully (and maybe transmit a bug report to some server you own so that the issue can be corrected, if you want to be really helpful); not hide this information in some file that most users probably wouldn’t think to check (much less realize exist).

SDL2 provides a messagebox functionality (SDL_messagebox.h) just for that. At least on Windows, it does not even require any SDL subsystems to be initialized, so it can be used even in the case of an error in SDL_Init (from a quick look on the source code, this seems to be true of the X11 and Cocoa implementations too, but I’m not that familiar with those APIs).------------------------
Nate Fries

Isn’r http://wiki.libsdl.org/SDL_RWops what you’re looking for?

SDL2 hooks SDL_Log on Win32 to WriteConsole() which outputs text to the
current (or parent) console buffer. This enables text logging even from
a windowed app when it is launched from a cmd window (i.e.open cmd, run
C:>testsprite2.exe). It also prints the same text to the debug console
when running under Visual Studio in debug mode using
OutputDebugString(). However the employed Win32 API does NOT allow
redirection of the logged text to a file as one would expect under Unix.

If you want file output, you’d have to make your own Custom_Log()
passthrough function that does that. See for example the source code for
SDLTest_Log() in SDL/src/test/SDL_test_log.c that implements such as
wrapper to precede each log line with a timestamp. It should be easy to
implement a variation that also writes the string to a file handle
before the standard log function is called.

–AndreasOn 8/26/2013 6:05 PM, JeZ-l-Lee wrote:

[SDL2]-Output SDL Info To Text File In EXE Folder?

Hi,

Old SDL 1.2 allowed output to “stdout” and “stderr” text files in
EXE’s folder.
New SDL 2.0 does not allow this.
How can I output SDL2 info into a text file in the EXE’s folder on
Windows®?

Thanks!

I tried this code, but no “stderr” or “stdout” files are found in the
EXE folder?:

Code:
if ( SDL_Init(SDL_INIT_EVERYTHING) != 0 )
{
fprintf( stderr, “Unable to initialize SDL: %s\n”, SDL_GetError() );
return(1);
}
else fprintf(stdout, “SDL initialized.\n”);


JeZ+Lee
JessePalser Gmail com
16BitSoft®
Video Game Design Studio
www.16BitSoft.com http://www.16BitSoft.com


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org