From 109bc3979b989969fdfba947286c771623d6b69a Mon Sep 17 00:00:00 2001 From: David Ludwig Date: Tue, 15 Aug 2017 21:41:59 -0400 Subject: [PATCH] implemented issue #7: output stdout and stderr to a log file; removed output redirection to win32 console, which was buggy --- BasiliskII/src/Windows/main_windows.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/BasiliskII/src/Windows/main_windows.cpp b/BasiliskII/src/Windows/main_windows.cpp index 9fa4e1c0..f54e595a 100755 --- a/BasiliskII/src/Windows/main_windows.cpp +++ b/BasiliskII/src/Windows/main_windows.cpp @@ -212,12 +212,25 @@ int main(int argc, char **argv) char str[256]; bool cd_boot = false; - // Make sure stdout and stderr gets displayed, if and when the app is run - // via a command prompt window. - if (AttachConsole(ATTACH_PARENT_PROCESS)) { - freopen("CONOUT$", "w", stdout); - freopen("CONOUT$", "w", stderr); - } + // Redirect stdout and stderr to a log file, for diagnostic purposes. + // Unbuffered file IO will be used (setup via setvbuf() calls), so as + // to write log file data ASAP, lest it get lost in case of program + // termination. + wchar_t logFileName[4096]; + logFileName[0] = L'\0'; + _wgetcwd(logFileName, SDL_arraysize(logFileName)); + if (logFileName[0] != L'\0') { + SDL_wcslcat(logFileName, L"\\BasiliskII_log.txt", SDL_arraysize(logFileName)); + FILE * fp; + fp = _wfreopen(logFileName, L"w", stdout); + if (fp) { + setvbuf(stdout, NULL, _IONBF, 0); + } + fp = _wfreopen(logFileName, L"w", stderr); + if (fp) { + setvbuf(stderr, NULL, _IONBF, 0); + } + } // Initialize variables RAMBaseHost = NULL;