diff options
author | Kai Koehne <kai.koehne@digia.com> | 2014-07-11 09:32:39 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@digia.com> | 2014-07-11 14:18:31 +0200 |
commit | e6390254c683d210ca837eb137b027146fdd9d3a (patch) | |
tree | 9985e45ba4c8583b788cf15f3a4efc04a2d5fc7f | |
parent | 6e7ff8a60ba2bf3dcab1646f0046fc4ef7066cb3 (diff) |
Windows: Write verbose output into parent console
Don't open a new console window for verbose output if we got
launched from a console already, but attach to the parent
console.
This allows users to e.g. pipe the verbose output to a file.
Change-Id: Ie602bdd18ef48b576e4b90806541709394882735
Reviewed-by: Niels Weber <niels.weber@digia.com>
Reviewed-by: Karsten Heimrich <karsten.heimrich@digia.com>
-rw-r--r-- | Changelog | 1 | ||||
-rw-r--r-- | src/sdk/console.h | 16 |
2 files changed, 13 insertions, 4 deletions
@@ -19,6 +19,7 @@ - Renamed settings inside config.xml: - UninstallerName renamed to MaintenanceToolName (default value changed to "maintenancetool") - UninstallerIniFile renamed to MaintenanceToolIniFile +- Windows: Re-use parent console for verbose output if possible Thanks go to Sze Howe Koh, Ray Donnelly and Sascha Cunz for contributions. diff --git a/src/sdk/console.h b/src/sdk/console.h index 7eb4aa3f4..8e627574d 100644 --- a/src/sdk/console.h +++ b/src/sdk/console.h @@ -68,6 +68,10 @@ class Console public: Console() { + parentConsole = AttachConsole(ATTACH_PARENT_PROCESS); + if (parentConsole) + return; + AllocConsole(); HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); if (handle != INVALID_HANDLE_VALUE) { @@ -102,16 +106,20 @@ public: ~Console() { - system("PAUSE"); + if (!parentConsole) { + system("PAUSE"); - std::cin.rdbuf(m_oldCin); - std::cerr.rdbuf(m_oldCerr); - std::cout.rdbuf(m_oldCout); + std::cin.rdbuf(m_oldCin); + std::cerr.rdbuf(m_oldCerr); + std::cout.rdbuf(m_oldCout); + } FreeConsole(); } private: + bool parentConsole; + std::ifstream m_newCin; std::ofstream m_newCout; std::ofstream m_newCerr; |