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 3990 - SDL_Log not working on windows when output is being redirected
Summary: SDL_Log not working on windows when output is being redirected
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: HG 2.0
Hardware: All Windows 10
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-04 17:34 UTC by Olli Kallioinen
Modified: 2017-12-05 04:27 UTC (History)
1 user (show)

See Also:


Attachments
Fixed SDL_Log not working on windows if the output is being redirected. (2.20 KB, patch)
2017-12-04 17:35 UTC, Olli Kallioinen
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olli Kallioinen 2017-12-04 17:34:11 UTC
SDL_Log and the other logging functions use WriteConsole() on Windows to print the log messages, but that only works if the output is an actual windows console (see https://docs.microsoft.com/en-us/windows/console/writeconsole).

For example if I run my application using something like:
 myapp.exe > output.txt 2>&1

that would redirect both the stdout and stderr to a file -> the calls to SDL_Log just fail. I have the same problem when running the application from the CLion IDE. I don't know how it handles the console but all calls to WriteConsole fail.

I made a patch that detects when the output handle is not a console (as mentioned in the above link) and uses WriteFile then instead. That seems to fix both the problems I was having.

As a side note: the indentation in SDL_log.c was a bit all over the place, but I didn't touch it to make it clearer what was changed.
Comment 1 Olli Kallioinen 2017-12-04 17:35:16 UTC
Created attachment 3108 [details]
Fixed SDL_Log not working on windows if the output is being redirected.
Comment 2 Sam Lantinga 2017-12-05 04:27:04 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/9cbb45a5874f