Skip to content

Instantly share code, notes, and snippets.

@technoburst
Last active February 3, 2022 16:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technoburst/5369746 to your computer and use it in GitHub Desktop.
Save technoburst/5369746 to your computer and use it in GitHub Desktop.
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