From 6ea22a1a9ef9d9be25e09740aa72bb0a5dfebfc7 Mon Sep 17 00:00:00 2001 From: Arttu Tarkiainen Date: Thu, 16 May 2019 12:06:28 +0300 Subject: Fix installer hang on Windows with empty command prompt window appearing Installer sometimes hangs on Windows with a command prompt window opening and blocking any progress. Hitting enter in this command prompt window causes progress to move forward. This blocks automated execution of tests since it requires manual interaction. parentConsole boolean was not initialized properly, fix logically broken closing actions for console. Task-number: QTIFW-1250 Change-Id: I062c0491c16c26e9435022d79f99240bf59e1a79 Reviewed-by: Katja Marttila --- src/sdk/console.h | 3 ++- src/sdk/console_win.cpp | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src/sdk') diff --git a/src/sdk/console.h b/src/sdk/console.h index 0ab6e4743..378a37e60 100644 --- a/src/sdk/console.h +++ b/src/sdk/console.h @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -44,6 +44,7 @@ public: private: bool parentConsole; + bool newConsoleCreated; std::ofstream m_newCout; std::ofstream m_newCerr; diff --git a/src/sdk/console_win.cpp b/src/sdk/console_win.cpp index f3226bc60..978159612 100644 --- a/src/sdk/console_win.cpp +++ b/src/sdk/console_win.cpp @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -74,7 +74,9 @@ static bool isRedirected(HANDLE stdHandle) */ Console::Console() : m_oldCout(nullptr), - m_oldCerr(nullptr) + m_oldCerr(nullptr), + parentConsole(false), + newConsoleCreated(false) { bool isCoutRedirected = isRedirected(GetStdHandle(STD_OUTPUT_HANDLE)); bool isCerrRedirected = isRedirected(GetStdHandle(STD_ERROR_HANDLE)); @@ -83,6 +85,7 @@ Console::Console() : // try to use parent console. else launch & set up new console parentConsole = AttachConsole(ATTACH_PARENT_PROCESS); if (!parentConsole) { + newConsoleCreated = true; AllocConsole(); HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); if (handle != INVALID_HANDLE_VALUE) { @@ -119,11 +122,11 @@ Console::Console() : Console::~Console() { - if (!parentConsole) { - system("PAUSE"); - } else { + if (parentConsole) { // simulate enter key to switch to boot prompt PostMessage(GetConsoleWindow(), WM_KEYDOWN, 0x0D, 0); + } else if (newConsoleCreated) { + system("PAUSE"); } if (m_oldCerr) -- cgit v1.2.3