From 953b899f75caad1173900cb3752ede0ce14dd8cf Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 2 Nov 2021 22:50:13 +0100 Subject: [PATCH] [libcalamares] Allow Runner instances to collect output --- src/libcalamares/utils/Runner.cpp | 20 ++++++++++++++------ src/libcalamares/utils/Runner.h | 4 ---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/libcalamares/utils/Runner.cpp b/src/libcalamares/utils/Runner.cpp index db783f676..36bb1bd2b 100644 --- a/src/libcalamares/utils/Runner.cpp +++ b/src/libcalamares/utils/Runner.cpp @@ -94,12 +94,6 @@ namespace Calamares namespace Utils { -struct Runner::Private -{ - QProcess m_process; -}; - - Runner::Runner() {} @@ -147,6 +141,20 @@ Calamares::Utils::Runner::run() process.setArguments( m_command ); } + if ( m_output ) + { + connect( &process, &QProcess::readyReadStandardOutput, [this, &process]() { + while ( process.canReadLine() ) + { + QString s = process.readLine(); + if ( !s.isEmpty() ) + { + Q_EMIT this->output( s ); + } + } + } ); + } + cDebug() << Logger::SubEntry << "Running" << Logger::Redacted( m_command ); process.start(); if ( !process.waitForStarted() ) diff --git a/src/libcalamares/utils/Runner.h b/src/libcalamares/utils/Runner.h index b41da07ab..510ddf098 100644 --- a/src/libcalamares/utils/Runner.h +++ b/src/libcalamares/utils/Runner.h @@ -109,10 +109,6 @@ private: QString m_input; std::chrono::milliseconds m_timeout { 0 }; bool m_output = false; - - // Internals for when it really does run - struct Private; - std::unique_ptr< Private > d; }; } // namespace Utils