Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start a Shell Script with QProcess?

How can I start a Shell Script using QProcess? The Shell Script has eight different commands in it, some with arguments others without.

I tried to start the Shell Script with (using Ubuntu 11.10):

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

But this doesn't work, that means nothing happens. How to make it work?

like image 880
Streight Avatar asked Jan 31 '12 20:01

Streight


People also ask

What is $$ in shell script?

$$ The process number of the current shell. For shell scripts, this is the process ID under which they are executing. 8.


2 Answers

Code is fine. Problem is at run-time.

Either your program can't run /bin/sh for some reason (test if you can run gedit instead?), or the MainDirectory variable has wrong directory path (debug it), or the Shell.sh does not exist in that directory (capitalization mistakes? What about "./Shell.sh"?), or you don't have enough privileges to run or modify target directory/files (are they owned by you?).

like image 136
Hossein Avatar answered Oct 19 '22 23:10

Hossein


The process you have started is running in background. if you want to see any explicit output from the running script you have to connect to void readyReadStandardOutput() or/and void readyReadStandardError() and read from the process explicitly. For example:

void onReadyRead() {

   QByteArray processOutput = Prozess->readAllStandardOutput();
}
like image 37
Neox Avatar answered Oct 19 '22 23:10

Neox