How to run a script shell using QProcess?

How to run a script shell using QProcess? The Script shell has eight different commands in it, some with the arguments of others without.

I tried to run the Script shell using (using Ubuntu 11.10):

QProcess *Prozess = new QProcess(); Prozess->setWorkingDirectory(MainDirectory); Prozess->start("/bin/sh", QStringList() << "Shell.sh"); 

But it does not work, it means that nothing is happening. How to make it work?

+4
source share
3 answers

The code is ok. The problem is at runtime.

Either your program cannot run /bin/sh for any reason (check whether gedit can be run instead?), Or the MainDirectory variable has the wrong directory path (debugging it) or Shell.sh does not exist in this directory (errors capitalization?) What is "./Shell.sh"?), or you do not have sufficient rights to run or modify the target directory / files (do they belong to you?).

+4
source

The process you started runs in the background. if you want to see any explicit output from a running script, you need to connect to void readyReadStandardOutput() or / and void readyReadStandardError() and explicitly read from the process. For instance:

 void onReadyRead() { QByteArray processOutput = Prozess->readAllStandardOutput(); } 
+1
source

This should work:

 QProcess::ProcessError Error = myProcess->readAllStandardError(); return Error; 
0
source

Source: https://habr.com/ru/post/1394060/


All Articles