From 86064979b47ad88d8eb487a663cc0cb9613a79e9 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Mon, 14 Aug 2023 14:28:23 +0200 Subject: [PATCH] Add memeber-variable for exitCode of executed process. --- process/command.cpp | 5 +++-- process/command.h | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/process/command.cpp b/process/command.cpp index 4b9047a..3f0f3e9 100644 --- a/process/command.cpp +++ b/process/command.cpp @@ -8,7 +8,8 @@ Command::Command(QString const &command, int start_timeout, int finish_timeout) : m_command(command.trimmed()) , m_commandResult("") , m_waitForStartTimeout(start_timeout) - , m_waitForFinishTimeout(finish_timeout) { + , m_waitForFinishTimeout(finish_timeout) + , m_exitCode(-1) { } QString Command::getCommandResult() const { @@ -62,7 +63,7 @@ bool Command::execute(QString workingDirectory, QStringList args) { if (p->waitForFinished(m_waitForFinishTimeout)) { //qDebug() << "PROCESS" << m_command << "FINISHED"; if (p->exitStatus() == QProcess::NormalExit) { - if (p->exitCode() == 0) { + if ((m_exitCode = p->exitCode()) == 0) { return true; } else { qCritical() << "EXECUTED" << m_command << "with code" << p->exitCode(); diff --git a/process/command.h b/process/command.h index 6b79543..bc796ee 100644 --- a/process/command.h +++ b/process/command.h @@ -16,15 +16,17 @@ class Command : public QObject { QString m_commandResult; int m_waitForStartTimeout; int m_waitForFinishTimeout; - + int m_exitCode; public: explicit Command(QString const &command, int start_timeout = 100000, int finish_timeout = 100000); QString getCommandResult() const; + QString command() const { return m_command; } bool execute(QString workingDirectory, QStringList args = QStringList()); + int exitCode() const { return m_exitCode; } private slots: void readyReadStandardOutput();