#includeint main() { QProcess process; process.start("ls", QStringList() << "-la"); // launch 'ls -la' command process.waitForFinished(); // wait for the command to finish QByteArray output = process.readAllStandardOutput(); // get the command output qDebug() << output; return 0; }
#includeint main() { QProcess process; process.startDetached("firefox", QStringList() << "https://www.google.com"); // launch firefox with google.com return 0; }
#includeIn this example, we launch the `bc` command (a calculator program) and send the input `1 + 2` to it. We then close the input channel and wait for the process to finish before getting the output and printing it.int main() { QProcess process; process.start("bc"); // launch the bc command process.waitForStarted(); // wait for the process to start process.write("1 + 2\n"); // send input to the process process.closeWriteChannel(); // close the input channel process.waitForFinished(); // wait for the process to finish QByteArray output = process.readAllStandardOutput(); // get the output qDebug() << output; return 0; }