From d4488ff69098d4d6d285703c19acd194febcc0b6 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 28 Aug 2017 15:47:57 +0100 Subject: [PATCH] Re-use parent console if it's available * This means we won't get an ugly console window popping up when running renderdoccmd on windows, but if we run it from a terminal then we'll get output as normal. * One downside is that cmd.exe seems to snoop the exe type (GUI or console) and if it's a GUI application it returns to the prompt immediately. bash for example though waits for process termination. * The other is that pipe redirects to file don't work properly. --- renderdoccmd/renderdoccmd_win32.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/renderdoccmd/renderdoccmd_win32.cpp b/renderdoccmd/renderdoccmd_win32.cpp index f7cd7bdec..c0ae1d5c5 100644 --- a/renderdoccmd/renderdoccmd_win32.cpp +++ b/renderdoccmd/renderdoccmd_win32.cpp @@ -808,6 +808,15 @@ int WINAPI wWinMain(_In_ HINSTANCE hInst, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR *wargv; int argc; + if(AttachConsole(ATTACH_PARENT_PROCESS)) + { + freopen("CONOUT$", "w", stdout); + freopen("CONOUT$", "w", stderr); + + std::cout.sync_with_stdio(); + std::cerr.sync_with_stdio(); + } + wargv = CommandLineToArgvW(GetCommandLine(), &argc); std::vector argv;