From 3e330b7929948f1e69178123f403625871f457f9 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 27 Aug 2022 14:54:45 -0500 Subject: [PATCH] Attach to the parent console to print list output on Win32 --- app/main.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/main.cpp b/app/main.cpp index e5bf7ecf..f4ceebc1 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -492,6 +492,22 @@ int main(int argc, char *argv[]) #ifdef USE_CUSTOM_LOGGER // Don't log to the console since it will jumble the command output s_SuppressVerboseOutput = true; +#endif +#ifdef Q_OS_WIN32 + // Attach to the console to be able to print output. + // Since we're a /SUBSYSTEM:WINDOWS app, we won't be attached by default. + if (AttachConsole(ATTACH_PARENT_PROCESS)) { + HANDLE conOut = GetStdHandle(STD_OUTPUT_HANDLE); + if (conOut != INVALID_HANDLE_VALUE && conOut != NULL) { + freopen("CONOUT$", "w", stdout); + setvbuf(stdout, NULL, _IONBF, 0); + } + HANDLE conErr = GetStdHandle(STD_ERROR_HANDLE); + if (conErr != INVALID_HANDLE_VALUE && conErr != NULL) { + freopen("CONOUT$", "w", stderr); + setvbuf(stderr, NULL, _IONBF, 0); + } + } #endif break; default: