Allow selecting different channels in ExternalCommand output.
This commit is contained in:
parent
fd68f9334c
commit
2a118753ae
|
@ -29,7 +29,7 @@
|
||||||
@param cmd the command to run
|
@param cmd the command to run
|
||||||
@param args the arguments to pass to the command
|
@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(),
|
QProcess(),
|
||||||
m_Report(nullptr),
|
m_Report(nullptr),
|
||||||
m_Command(cmd),
|
m_Command(cmd),
|
||||||
|
@ -37,7 +37,7 @@ ExternalCommand::ExternalCommand(const QString& cmd, const QStringList& args) :
|
||||||
m_ExitCode(-1),
|
m_ExitCode(-1),
|
||||||
m_Output()
|
m_Output()
|
||||||
{
|
{
|
||||||
setup();
|
setup(processChannelMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Creates a new ExternalCommand instance with Report.
|
/** 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 cmd the command to run
|
||||||
@param args the arguments to pass to the command
|
@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(),
|
QProcess(),
|
||||||
m_Report(report.newChild()),
|
m_Report(report.newChild()),
|
||||||
m_Command(cmd),
|
m_Command(cmd),
|
||||||
|
@ -53,13 +53,13 @@ ExternalCommand::ExternalCommand(Report& report, const QString& cmd, const QStri
|
||||||
m_ExitCode(-1),
|
m_ExitCode(-1),
|
||||||
m_Output()
|
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"));
|
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, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &ExternalCommand::onFinished);
|
||||||
connect(this, &ExternalCommand::readyReadStandardOutput, this, &ExternalCommand::onReadOutput);
|
connect(this, &ExternalCommand::readyReadStandardOutput, this, &ExternalCommand::onReadOutput);
|
||||||
|
|
|
@ -42,8 +42,8 @@ class LIBKPMCORE_EXPORT ExternalCommand : public QProcess
|
||||||
Q_DISABLE_COPY(ExternalCommand)
|
Q_DISABLE_COPY(ExternalCommand)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ExternalCommand(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());
|
explicit ExternalCommand(Report& report, const QString& cmd = QString(), const QStringList& args = QStringList(), const QProcess::ProcessChannelMode processChannelMode = MergedChannels);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setCommand(const QString& cmd) { m_Command = cmd; } /**< @param cmd the command to run */
|
void setCommand(const QString& cmd) { m_Command = cmd; } /**< @param cmd the command to run */
|
||||||
|
@ -73,7 +73,7 @@ protected:
|
||||||
void setExitCode(int i) {
|
void setExitCode(int i) {
|
||||||
m_ExitCode = i;
|
m_ExitCode = i;
|
||||||
}
|
}
|
||||||
void setup();
|
void setup(const QProcess::ProcessChannelMode processChannelMode);
|
||||||
|
|
||||||
void onFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
void onFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||||
void onReadOutput();
|
void onReadOutput();
|
||||||
|
|
Loading…
Reference in New Issue