QProcess process; process.setProgram("/bin/ls"); process.setArguments({"-l", "/home"}); process.setReadChannelMode(QProcess::StandardOutput); process.start(); // read the standard output channel of the ls command QByteArray output = process.readAllStandardOutput(); qDebug() << "Output of ls command:"; qDebug() << output;
QProcess process; process.setProgram("/bin/echo"); process.setArguments({"hello", "world"}); process.setReadChannelMode(QProcess::MergedChannels); process.start(); // read the merged output and error channels of the echo command QByteArray output = process.readAll(); qDebug() << "Output of echo command:"; qDebug() << output;In this example, we use setReadChannelMode to set the read channel to the merged output and error channels of the echo command. We then start the process and read the output with the readAll method. The output is then displayed using qDebug. Package library: Qt Core