From 7ea413f202d5716de7155df46e708ce5825771d1 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 16 Feb 2018 12:15:33 +0100 Subject: gui: attach parent console harder --- gui/init.cpp | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'gui') diff --git a/gui/init.cpp b/gui/init.cpp index 1de98f60..5879c6c0 100644 --- a/gui/init.cpp +++ b/gui/init.cpp @@ -143,7 +143,26 @@ void add_win32_path() } } -void attach_parent_console(); +#include + +void attach_parent_console() +{ + std::fflush(stdin); + std::fflush(stderr); + + (void)qInstallMessageHandler(qdebug_to_console); + + if (AttachConsole(ATTACH_PARENT_PROCESS)) + { + _wfreopen(L"CON", L"w", stdout); + _wfreopen(L"CON", L"w", stderr); + _wfreopen(L"CON", L"r", stdin); + + freopen("CON", "w", stdout); + freopen("CON", "w", stderr); + freopen("CON", "w", stderr); + } +} #endif @@ -214,19 +233,3 @@ int otr_main(int argc, char** argv, std::function make_main_window) return ret; } -#if defined _WIN32 -#include - -void attach_parent_console() -{ - if (AttachConsole(ATTACH_PARENT_PROCESS)) - { - // XXX c++ iostreams aren't reopened - - _wfreopen(L"CON", L"w", stdout); - _wfreopen(L"CON", L"w", stderr); - _wfreopen(L"CON", L"r", stdin); - } - (void)qInstallMessageHandler(qdebug_to_console); -} -#endif -- cgit v1.2.3