Created
May 30, 2024 07:03
-
-
Save mitchcurtis/1388f4ac1198de486ff0f8af359857a7 to your computer and use it in GitHub Desktop.
Execute shell script using QProcess
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QCoreApplication> | |
#include <QProcess> | |
#include <QDebug> | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication app(argc, argv); | |
QProcess process; | |
QObject::connect(&process, &QProcess::errorOccurred, [&process](){ | |
qWarning() << "Error starting shell:" << process.errorString(); | |
QCoreApplication::quit(); | |
}); | |
QObject::connect(&process, &QProcess::readyReadStandardOutput, [&process](){ | |
qDebug() << process.readAllStandardOutput(); | |
}); | |
QObject::connect(&process, &QProcess::readyReadStandardError, [&process](){ | |
qWarning() << "Error running script:" << process.readAllStandardError(); | |
}); | |
QObject::connect(&process, &QProcess::finished, [&process](){ | |
QCoreApplication::quit(); | |
}); | |
process.start("/usr/bin/sh", { "-c", "echo hello" }); | |
return app.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment