From 8667211180c7d93c8a009d5886c95655d6066507 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Wed, 5 Aug 2020 21:49:11 -0500 Subject: [PATCH] Move console attachment to main and only perform if running in a terminal. (!102) --- cli.cpp | 10 ---------- main.cpp | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/cli.cpp b/cli.cpp index c1dcfdae..872ffc8a 100644 --- a/cli.cpp +++ b/cli.cpp @@ -1016,16 +1016,6 @@ unsigned int cli_main(int argc, char *argv[], std::vector &rgb_ profile_manager = profile_manager_in; network_server = network_server_in; - /*---------------------------------------------------------*\ - | Windows only - Attach console output | - \*---------------------------------------------------------*/ -#ifdef _WIN32 - AttachConsole(-1); - freopen("CONIN$", "r", stdin); - freopen("CONOUT$", "w", stdout); - freopen("CONOUT$", "w", stderr); -#endif - /*---------------------------------------------------------*\ | Process the argument options | \*---------------------------------------------------------*/ diff --git a/main.cpp b/main.cpp index c1765444..67c2dea8 100644 --- a/main.cpp +++ b/main.cpp @@ -127,6 +127,20 @@ bool AttemptLocalConnection(std::vector &rgb_controllers) int main(int argc, char* argv[]) { #ifdef _WIN32 + /*---------------------------------------------------------*\ + | Windows only - Attach console output | + \*---------------------------------------------------------*/ + if (AttachConsole(ATTACH_PARENT_PROCESS)) + { + /*---------------------------------------------------------*\ + | We are running under some terminal context; otherwise | + | leave the GUI and CRT alone | + \*---------------------------------------------------------*/ + freopen("CONIN$", "r", stdin); + freopen("CONOUT$", "w", stdout); + freopen("CONOUT$", "w", stderr); + } + std::thread * InitializeTimerResolutionThread; InitializeTimerResolutionThread = new std::thread(InitializeTimerResolutionThreadFunction); InitializeTimerResolutionThread->detach();