From 2a118753ae5f6ea3f7731ef5044b9d2e9070467b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Sat, 26 Aug 2017 18:40:28 +0100 Subject: [PATCH] Allow selecting different channels in ExternalCommand output. --- src/util/externalcommand.cpp | 12 ++++++------ src/util/externalcommand.h | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/util/externalcommand.cpp b/src/util/externalcommand.cpp index dfd80e9..225b99c 100644 --- a/src/util/externalcommand.cpp +++ b/src/util/externalcommand.cpp @@ -29,7 +29,7 @@ @param cmd the command to run @param args the arguments to pass to the command */ -ExternalCommand::ExternalCommand(const QString& cmd, const QStringList& args) : +ExternalCommand::ExternalCommand(const QString& cmd, const QStringList& args, const QProcess::ProcessChannelMode processChannelMode) : QProcess(), m_Report(nullptr), m_Command(cmd), @@ -37,7 +37,7 @@ ExternalCommand::ExternalCommand(const QString& cmd, const QStringList& args) : m_ExitCode(-1), m_Output() { - setup(); + setup(processChannelMode); } /** Creates a new ExternalCommand instance with Report. @@ -45,7 +45,7 @@ ExternalCommand::ExternalCommand(const QString& cmd, const QStringList& args) : @param cmd the command to run @param args the arguments to pass to the command */ -ExternalCommand::ExternalCommand(Report& report, const QString& cmd, const QStringList& args) : +ExternalCommand::ExternalCommand(Report& report, const QString& cmd, const QStringList& args, const QProcess::ProcessChannelMode processChannelMode) : QProcess(), m_Report(report.newChild()), m_Command(cmd), @@ -53,13 +53,13 @@ ExternalCommand::ExternalCommand(Report& report, const QString& cmd, const QStri m_ExitCode(-1), m_Output() { - setup(); + setup(processChannelMode); } -void ExternalCommand::setup() +void ExternalCommand::setup(const QProcess::ProcessChannelMode processChannelMode) { setEnvironment(QStringList() << QStringLiteral("LC_ALL=C") << QStringLiteral("PATH=") + QString::fromUtf8(getenv("PATH")) << QStringLiteral("LVM_SUPPRESS_FD_WARNINGS=1")); - setProcessChannelMode(SeparateChannels); + setProcessChannelMode(processChannelMode); connect(this, static_cast(&QProcess::finished), this, &ExternalCommand::onFinished); connect(this, &ExternalCommand::readyReadStandardOutput, this, &ExternalCommand::onReadOutput); diff --git a/src/util/externalcommand.h b/src/util/externalcommand.h index e63cc30..4c9c306 100644 --- a/src/util/externalcommand.h +++ b/src/util/externalcommand.h @@ -42,8 +42,8 @@ class LIBKPMCORE_EXPORT ExternalCommand : public QProcess Q_DISABLE_COPY(ExternalCommand) public: - explicit ExternalCommand(const QString& cmd = QString(), const QStringList& args = QStringList()); - explicit ExternalCommand(Report& report, const QString& cmd = QString(), const QStringList& args = QStringList()); + explicit ExternalCommand(const QString& cmd = QString(), const QStringList& args = QStringList(), const QProcess::ProcessChannelMode processChannelMode = MergedChannels); + explicit ExternalCommand(Report& report, const QString& cmd = QString(), const QStringList& args = QStringList(), const QProcess::ProcessChannelMode processChannelMode = MergedChannels); public: void setCommand(const QString& cmd) { m_Command = cmd; } /**< @param cmd the command to run */ @@ -73,7 +73,7 @@ protected: void setExitCode(int i) { m_ExitCode = i; } - void setup(); + void setup(const QProcess::ProcessChannelMode processChannelMode); void onFinished(int exitCode, QProcess::ExitStatus exitStatus); void onReadOutput();