Last active
September 20, 2024 08:57
Sample qt program to execute Linux commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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