diff --git a/app/main.cpp b/app/main.cpp index 14dd9bbf1..b3287d85f 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -42,12 +42,41 @@ extern "C" { #include "common/debug.h" #include "version.h" +#ifdef _WIN32 +#include +#endif + #ifdef USE_CRASHPAD #include "common/crashpadinterface.h" #endif // USE_CRASHPAD int main(int argc, char *argv[]) { + +#ifdef _WIN32 + bool console = false; + FILE *stream_stdout; + FILE *stream_stderr; + + AttachConsole(ATTACH_PARENT_PROCESS); + DWORD procIDs[2]; + DWORD maxIds = 2; + DWORD count = GetConsoleProcessList((LPDWORD)procIDs, maxIds); + + if (count == 2) { + /* this is a terminal */ + FreeConsole(); + + // Create own console + if (AllocConsole()) { + freopen_s(&stream_stdout, "CONOUT$", "w", stdout); + freopen_s(&stream_stderr, "CONOUT$", "w", stderr); + console = true; + } + + } +#endif + // Set up debug handler qInstallMessageHandler(olive::DebugHandler); @@ -208,5 +237,11 @@ int main(int argc, char *argv[]) // Clear core memory c.Stop(); + #ifdef _WIN32 + if (console) { + system("pause"); + } + #endif + return ret; }