Improved debug output.

This commit is contained in:
Gerhard Hoffmann 2023-08-16 10:39:46 +02:00
parent e700a40875
commit 0f2ee0349f

View File

@ -2,6 +2,7 @@
#include <QProcess> #include <QProcess>
#include <QDebug> #include <QDebug>
#include <QDir>
#include <QRegularExpression> #include <QRegularExpression>
Command::Command(QString const &command, int start_timeout, int finish_timeout) Command::Command(QString const &command, int start_timeout, int finish_timeout)
@ -40,46 +41,64 @@ void Command::finished(int /*exitCode*/, QProcess::ExitStatus /*exitStatus*/) {
} }
bool Command::execute(QString workingDirectory, QStringList args) { bool Command::execute(QString workingDirectory, QStringList args) {
if (!QDir::setCurrent(workingDirectory)) {
qCritical() << "SET WORKING_DIRECTORY" << workingDirectory
<< "FAILED FOR" << m_command;
return false;
}
QScopedPointer<QProcess> p(new QProcess(this)); QScopedPointer<QProcess> p(new QProcess(this));
p->setWorkingDirectory(workingDirectory);
p->setProcessChannelMode(QProcess::MergedChannels); p->setProcessChannelMode(QProcess::MergedChannels);
connect(&(*p), SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput())); connect(&(*p), SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput()));
connect(&(*p), SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError())); connect(&(*p), SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError()));
//qCritical() << "START COMMAND" << m_command << "WITH ARGS" << args
// << "IN" << workingDirectory;
p->setWorkingDirectory(workingDirectory);
if (!args.isEmpty()) { if (!args.isEmpty()) {
qDebug() << "START COMMAND" << m_command << "WITH ARGS" << args
<< "IN" << p->workingDirectory();
p->start(m_command, args); p->start(m_command, args);
} else { } else {
qDebug() << "START COMMAND" << m_command
<< "IN" << p->workingDirectory();
p->start(m_command); p->start(m_command);
} }
if (p->waitForStarted(m_waitForStartTimeout)) { if (p->waitForStarted(m_waitForStartTimeout)) {
//qDebug() << "PROCESS" << m_command << "STARTED"; qDebug() << "PROCESS" << m_command << "STARTED IN" << p->workingDirectory();
if (p->state() == QProcess::ProcessState::Running) { if (p->state() == QProcess::ProcessState::Running) {
//qDebug() << "PROCESS" << m_command << "RUNNING"; qDebug() << "PROCESS" << m_command << "RUNNING IN" << p->workingDirectory();
if (p->waitForFinished(m_waitForFinishTimeout)) { if (p->waitForFinished(m_waitForFinishTimeout)) {
//qDebug() << "PROCESS" << m_command << "FINISHED"; qDebug() << "PROCESS" << m_command << "FINISHED IN" << p->workingDirectory();
if (p->exitStatus() == QProcess::NormalExit) { if (p->exitStatus() == QProcess::NormalExit) {
if ((m_exitCode = p->exitCode()) == 0) { if ((m_exitCode = p->exitCode()) == 0) {
qDebug() << "EXECUTED" << m_command
<< "with code" << m_exitCode
<< "IN" << p->workingDirectory();
return true; return true;
} else { } else {
qCritical() << "EXECUTED" << m_command << "with code" << p->exitCode(); qCritical() << "EXECUTED" << m_command
<< "with code" << m_exitCode
<< "IN" << p->workingDirectory();
} }
} else { } else {
qCritical() << "PROCESS" << m_command << "CRASHED with code" qCritical() << "PROCESS" << m_command << "CRASHED with code"
<< p->exitCode(); << p->exitCode()
<< "IN" << p->workingDirectory();
} }
} else { } else {
qCritical() << "PROCESS" << m_command << "DID NOT FINISH"; qCritical() << "PROCESS" << m_command
<< "DID NOT FINISH"
<< "IN" << p->workingDirectory();
} }
} else { } else {
qCritical() << "WRONG PROCESS STATE" << p->state(); qCritical() << "WRONG PROCESS STATE" << p->state()
<< "IN" << p->workingDirectory();
} }
} else { } else {
qCritical() << "PROCESS" << m_command << "TIMEOUT AT START"; qCritical() << "PROCESS" << m_command << "TIMEOUT AT START"
<< "IN" << p->workingDirectory();
} }
return false; return false;
} }