diff options
author | Petr Mrázek <peterix@gmail.com> | 2016-06-09 01:58:50 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2016-06-10 00:58:30 +0200 |
commit | e07456f4bf2135bcb78cbd5ae1f10d1bbe45490c (patch) | |
tree | 9ba4f7a9fed9ba63c2e26bea304fd39840a81b5e | |
parent | 54e5a98da0d0e0c57120728be9d52e33e05a35c5 (diff) | |
download | MultiMC-e07456f4bf2135bcb78cbd5ae1f10d1bbe45490c.tar MultiMC-e07456f4bf2135bcb78cbd5ae1f10d1bbe45490c.tar.gz MultiMC-e07456f4bf2135bcb78cbd5ae1f10d1bbe45490c.tar.lz MultiMC-e07456f4bf2135bcb78cbd5ae1f10d1bbe45490c.tar.xz MultiMC-e07456f4bf2135bcb78cbd5ae1f10d1bbe45490c.zip |
GH-1586 Windows: attach to the parent process console if there is any, so command line output gets printed there
-rw-r--r-- | application/MultiMC.cpp | 41 | ||||
-rw-r--r-- | application/MultiMC.h | 2 |
2 files changed, 43 insertions, 0 deletions
diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index c9c7d41b..7b891215 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -52,10 +52,42 @@ #include <FileSystem.h> #include <DesktopServices.h> +#if defined Q_OS_WIN32 +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include <windows.h> +#include <stdio.h> +#endif + using namespace Commandline; MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, argv) { +#if defined Q_OS_WIN32 + // attach the parent console + if(AttachConsole(ATTACH_PARENT_PROCESS)) + { + // if attach succeeds, reopen and sync all the i/o + if(freopen("CON", "w", stdout)) + { + std::cout.sync_with_stdio(); + } + if(freopen("CON", "w", stderr)) + { + std::cerr.sync_with_stdio(); + } + if(freopen("CON", "r", stdin)) + { + std::cin.sync_with_stdio(); + } + auto out = GetStdHandle (STD_OUTPUT_HANDLE); + DWORD written; + const char * endline = "\n"; + WriteConsole(out, endline, strlen(endline), &written, NULL); + consoleAttached = true; + } +#endif setOrganizationName("MultiMC"); setApplicationName("MultiMC5"); @@ -279,6 +311,15 @@ MultiMC::~MultiMC() { removeTranslator(m_qt_translator.get()); } +#if defined Q_OS_WIN32 + if(consoleAttached) + { + const char * endline = "\n"; + auto out = GetStdHandle (STD_OUTPUT_HANDLE); + DWORD written; + WriteConsole(out, endline, strlen(endline), &written, NULL); + } +#endif } #ifdef Q_OS_MAC diff --git a/application/MultiMC.h b/application/MultiMC.h index 8219d66c..887f9c2d 100644 --- a/application/MultiMC.h +++ b/application/MultiMC.h @@ -176,6 +176,8 @@ private: QString rootPath; Status m_status = MultiMC::Failed; + + bool consoleAttached = false; public: QString launchId; std::shared_ptr<QFile> logFile; |