Stdout.txt and stderr.txt

When SDL programs run in win32, they create
stdout.txt and stderr.txt. This is good,
until I run a program under a read only
filesystem (ex. cdrom). This generate a crash.

Is there a way to avoid this?

Thanks, Enzo.

In Win32 it redirects the output to a file in the WinMain function. You
should be able to redirect it back to stdout by doing a freopen with "CON"
as the file eg:
freopen( “CON”, “w”, stdout );> ----- Original Message -----

When SDL programs run in win32, they create
stdout.txt and stderr.txt. This is good,
until I run a program under a read only
filesystem (ex. cdrom). This generate a crash.

Is there a way to avoid this?

Thanks, Enzo.

In Win32 it redirects the output to a file in the WinMain function. You
should be able to redirect it back to stdout by doing a freopen with "CON"
as the file eg:
freopen( “CON”, “w”, stdout );

You can also copy the src/main/win32/SDL_main.c file into your project and
then you will no longer need to link with SDLmain.lib, and you can change
the way the I/O redirection works.

I didn’t know it crashed SDL though, that should be fixed.

Thanks!
-Sam Lantinga (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

Sam Lantinga wrote:

You can also copy the src/main/win32/SDL_main.c file into your project and
then you will no longer need to link with SDLmain.lib, and you can change
the way the I/O redirection works.

I didn’t know it crashed SDL though, that should be fixed.

First the freopen fails and then the “second chance” fopen fails. At this
point it tries to do a structure copy into stdout using a null pointer on
the right hand side. You can simulate it by running an app, setting the
std
.txt files to read-only, and then running the app again. Looks like the
code is doing some special case stuff to get around an NT issue.

  • Randi

Regimental Command
Generic Armored Combat System
http://www-users.cs.umn.edu/~relander/regcom/index.html

Andrew Shakinovsky wrote:

In Win32 it redirects the output to a file in the WinMain function. You
should be able to redirect it back to stdout by doing a freopen with "CON"
as the file eg:
freopen( “CON”, “w”, stdout );

I’m having the same problem under winNT 4. I tried the above, but no joy
(I also tried “CON:” because of (very) vague memories of device names :slight_smile:

Does NT have a different name for the console ?

ATB,
Simon.

Andrew Shakinovsky wrote:

In Win32 it redirects the output to a file in the WinMain function. You
should be able to redirect it back to stdout by doing a freopen with "CON"
as the file eg:
freopen( “CON”, “w”, stdout );

I’m having the same problem under winNT 4. I tried the above, but no joy
(I also tried “CON:” because of (very) vague memories of device names :slight_smile:

Does NT have a different name for the console ?

As far as I know you only get console output when you build a "console"
application, one that brings up a black input/output window. That’s why
I redirect stdio to files.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

what would be nice is if it would output to console if run form console and to
files otherwise, not sure how easy that would be and i would be to lazy to do it
myself even if i did have some use for it but it would be nice :slight_smile:

Sam Lantinga wrote:> > Andrew Shakinovsky wrote:

In Win32 it redirects the output to a file in the WinMain function. You
should be able to redirect it back to stdout by doing a freopen with "CON"
as the file eg:
freopen( “CON”, “w”, stdout );

I’m having the same problem under winNT 4. I tried the above, but no joy
(I also tried “CON:” because of (very) vague memories of device names :slight_smile:

Does NT have a different name for the console ?

As far as I know you only get console output when you build a "console"
application, one that brings up a black input/output window. That’s why
I redirect stdio to files.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Sam Lantinga wrote:

Andrew Shakinovsky wrote:

In Win32 it redirects the output to a file in the WinMain function. You
should be able to redirect it back to stdout by doing a freopen with "CON"
as the file eg:
freopen( “CON”, “w”, stdout );

I’m having the same problem under winNT 4. I tried the above, but no joy
(I also tried “CON:” because of (very) vague memories of device names :slight_smile:

Does NT have a different name for the console ?

As far as I know you only get console output when you build a "console"
application, one that brings up a black input/output window. That’s why
I redirect stdio to files.

Hmm. I’m using mingw32 (2.95.2) and compiling with -mwindows options, I
don’t get a black box, but I do get the files in the cwd.

ATB,
Simon.

As far as I know you only get console output when you build a "console"
application, one that brings up a black input/output window. That’s why
I redirect stdio to files.

Hmm. I’m using mingw32 (2.95.2) and compiling with -mwindows options, I
don’t get a black box, but I do get the files in the cwd.

I don’t know about mingw32, but I know it exists with VC 6, but you need to toggle it specifically.

Question for the Windows-knowledgeable: When you differ between a “Win32 Application” and a “Win32 Console Application”,
what exactly changes? Maybe we could enforce console applications under Win32, and hence deal with this file export stuff, which
is really a kludge.

ATB,
Simon.

Nicholas

Its just a compile time option, which you can change at any point…
WIthout having VC6 in front of me, off the top of my head, its something
like this:

Under Project->Settings…
Errr, under the Link tab…
Theres a text box at the bottom with all sorts of gobbledygook in…
theres a switch followed by an option, which can be changed between
’windows’ and ‘console’ to change the type of application…change that in
both debug and release modes.

Vague, I know…but hopefully better than nothing.

Ben> ----- Original Message -----

From: vining@pacificcoast.net [mailto:vining at pacificcoast.net]
Sent: 04 April 2000 21:09
To: sdl at lokigames.com
Subject: Re: Re: [SDL] stdout.txt and stderr.txt

As far as I know you only get console output when you build a "console"
application, one that brings up a black input/output window. That’s why
I redirect stdio to files.

Hmm. I’m using mingw32 (2.95.2) and compiling with -mwindows options, I
don’t get a black box, but I do get the files in the cwd.

I don’t know about mingw32, but I know it exists with VC 6, but you need to
toggle it specifically.

Question for the Windows-knowledgeable: When you differ between a “Win32
Application” and a “Win32 Console Application”,
what exactly changes? Maybe we could enforce console applications under
Win32, and hence deal with this file export stuff, which
is really a kludge.

ATB,
Simon.

Nicholas

sdl at lokigames.com writes:

As far as I know you only get console output when you build a "console"
application, one that brings up a black input/output window. That’s
why

I redirect stdio to files.

Hmm. I’m using mingw32 (2.95.2) and compiling with -mwindows options, I
don’t get a black box, but I do get the files in the cwd.

I don’t know about mingw32, but I know it exists with VC 6, but you need
to toggle it specifically.

Question for the Windows-knowledgeable: When you differ between a “Win32
Application” and a “Win32 Console Application”,
what exactly changes? Maybe we could enforce console applications under
Win32, and hence deal with this file export stuff, which
is really a kludge.

ATB,
Simon.

Nicholas

I used to develop all my Win32/DX applications as console applications to
get quick and dirty stderr messages while debugging. Another benefit is
that you also can get rid of WinMain() and just use main(). I don’t know
what is the difference really is between a Console/Win32 app, but had
absolutely no problems compiling/running DX apps as a console app. As far
as I can remember (have been using SDL and not Win32/DX directly for quite
a while now), you just have to retrieve a couple values (HWND is one I
think) with calls to the Windows API since these values are not passed to
WinMain anymore. I can post the code if anyone is interested.

Kelly

I used to develop all my Win32/DX applications as console applications to
get quick and dirty stderr messages while debugging. Another benefit is
that you also can get rid of WinMain() and just use main(). I don’t know
what is the difference really is between a Console/Win32 app, but had
absolutely no problems compiling/running DX apps as a console app. As far
as I can remember (have been using SDL and not Win32/DX directly for quite
a while now), you just have to retrieve a couple values (HWND is one I
think) with calls to the Windows API since these values are not passed to
WinMain anymore. I can post the code if anyone is interested.

Go for it. This calls for further experimentation.

Kelly

Nicholas

Actually, all you need is the hInstance that used to be passed in
WinMain, and save the HWND where DX functions can read it. The relevant
parts of the code to create a window in a console app follow.

// Global
HWND gWinHandle; // DX functions will need this

BOOL InitOS(CHAR * appName)
{
HANDLE hInstance;
WNDCLASS wndClass;

// hInstance usually passed into WinMain
hInstance=GetModuleHandle(NULL);

wndClass.style = CS_DBLCLKS;
wndClass.lpfnWndProc = WindowProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = NULL;
wndClass.lpszMenuName = appName;
wndClass.lpszClassName = appName;
RegisterClass(&wndClass);

// Create the window like you normally would:
gWinHandle=CreateWindowEx(WS_EX_TOPMOST, appName, appName,
WS_VISIBLE|WS_POPUP, 0, 0,
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN),
NULL, NULL, hInstance, NULL);

// Set focus and show window like usual…

} // InitOS

Kelly

vining at pacificcoast.net wrote:>

I used to develop all my Win32/DX applications as console applications to
get quick and dirty stderr messages while debugging. Another benefit is
that you also can get rid of WinMain() and just use main(). I don’t know
what is the difference really is between a Console/Win32 app, but had
absolutely no problems compiling/running DX apps as a console app. As far
as I can remember (have been using SDL and not Win32/DX directly for quite
a while now), you just have to retrieve a couple values (HWND is one I
think) with calls to the Windows API since these values are not passed to
WinMain anymore. I can post the code if anyone is interested.

Go for it. This calls for further experimentation.

Kelly

Nicholas