QProcess process; process.start("ls"); process.waitForFinished(); QString output = process.readAllStandardOutput();
QProcess process; process.start("sort"); process.write("b\na\nc\n"); // write some data to the command's input stream process.closeWriteChannel(); // indicate that we finished providing input process.waitForFinished(); QString output = process.readAllStandardOutput();
QProcess process; process.setProgram("tar"); process.setArguments({"-czf", "archive.tgz", "mydir"}); process.start(); process.waitForFinished(); QString output = process.readAllStandardOutput(); QString error = process.readAllStandardError();In this example, we use the QProcess::setProgram() and QProcess::setArguments() methods to specify the "tar" command and its arguments. We start the command, wait for it to finish, and then read its standard output and error streams into separate QString variables. The Qt library package provides the QProcess class.