Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample qt program to execute Linux commands
//Author : Anil C S
//Website : www.technoburst.net
#include <iostream>
#include <QProcess>
using namespace std;
int main(int argc, char *argv[])
{
cout<<"\n * Program to demonstrate the usage of linux commands in qt * \n";
QProcess OProcess;
QString Command; //Contains the command to be executed
QStringList args; //Contains arguments of the command
Command = "ls";
args<<"-l"<<"/home/anil";
OProcess.start(Command,args,QIODevice::ReadOnly); //Starts execution of command
OProcess.waitForFinished(); //Waits for execution to complete
QString StdOut = OProcess.readAllStandardOutput(); //Reads standard output
QString StdError = OProcess.readAllStandardError(); //Reads standard error
cout<<"\n Printing the standard output..........\n";
cout<<endl<<StdOut.toStdString();
cout<<"\n Printing the standard error..........\n";
cout<<endl<<StdError.toStdString();
cout<<"\n\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment