How to make simple app for run some terminal commands
-
I want to make a simple application for my practice exam. This application is used to run some linux terminal commands such as
lsb_release -a
,dpkg -l (textbox)
,sudo apt update (on my xubuntu)
,sudo pacman -Syu (on my manjaro)
, and many more. I've started by creating a C++ based Qt Widget Application project. I've made the UI and now I'm confused, where should I put a command likeQProcess process1; process1.start("sudo lsb_release -a");
. Whereas QProcess is always said to be an error. For your information, the last time I used C++ was 2 years ago. And I have never had any experience using Python.``` -
Hi and welcome to the forums
First you should read the docs.
https://doc.qt.io/qt-5/qprocess.htmlPlease notice that any parameters should be included in the QStringList param and not as part of the string for the app.
QString program = "./path/to/app.exe"; QStringList arguments; arguments << "-arg1" << "arg2"; QProcess *myProcess = new QProcess(parent); myProcess->start(program, arguments);
so start("sudo lsb_release -a") is not right as "-a" should be on its own.
Then next is the fact that QProcess is asynchronous so make sure that you dont declare
QProcess process1 inside a function as it will then be deleted before anything happens.
So make it a class member.Then there is sudo. If it asks for password then it wont work.
About where to have the process1.start, Well how will app work ?
User must press something or its it automatic in some way ?