Allow selecting different channels in ExternalCommand output.

This commit is contained in:
Andrius Štikonas 2017-08-26 18:40:28 +01:00
parent fd68f9334c
commit 2a118753ae
2 changed files with 9 additions and 9 deletions

View File

@ -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<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &ExternalCommand::onFinished);
connect(this, &ExternalCommand::readyReadStandardOutput, this, &ExternalCommand::onReadOutput);

View File

@ -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();