#include#include int main(int argc, char *argv[]) { QProcess myProcess; myProcess.start("/bin/ls"); myProcess.waitForFinished(); QByteArray output = myProcess.readAllStandardOutput(); qDebug() << output; return 0; }
#includeThis example runs the "ping" command with an argument of "google.com". The output is then read and printed to the console. If the process fails to start or finish, an error message is printed. The package/library used is QtCore.#include int main(int argc, char *argv[]) { QProcess myProcess; myProcess.start("ping", QStringList() << "google.com"); if (!myProcess.waitForStarted()) { qDebug() << "Failed to start ping."; return 1; } if (!myProcess.waitForFinished()) { qDebug() << "Failed to finish ping."; return 1; } QByteArray output = myProcess.readAllStandardOutput(); qDebug() << output; return 0; }