-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcmd.cpp
More file actions
27 lines (24 loc) · 941 Bytes
/
cmd.cpp
File metadata and controls
27 lines (24 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "cmd.h"
#include <QDebug>
Cmd::Cmd(QObject *parent)
: QProcess(parent)
{
connect(this, &Cmd::readyReadStandardOutput, [this] { out_buffer += readAllStandardOutput(); });
connect(this, &Cmd::readyReadStandardError, [this] { out_buffer += readAllStandardError(); });
connect(this, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), [this](int exitCode, QProcess::ExitStatus exitStatus) {
bool success = (exitStatus == QProcess::NormalExit && exitCode == 0);
emit commandFinished(success, out_buffer.trimmed());
});
}
void Cmd::runAsync(const QString &program, const QStringList &args, Output output)
{
if (state() != QProcess::NotRunning) {
qDebug() << "Process already running:" << this->program() << arguments();
return;
}
out_buffer.clear();
if (output == Verbose) {
qDebug().noquote() << program << args;
}
start(program, args);
}