Execute Shell Script with button function

hi,

I have created a little GUI with QT Designer/Creator. Now I want to execute a Shell Script by pushing a button. I have already connected the button to a methode. In the method I now have to write the code for starting the Shell Script.

I tried it with the QProcess class:

1
2
3
4
5
QString program = "/bin/sh";
QString shellFile = "Shell.sh";
QProcess *myProcess = new QProcess(this);
myProcess->setStandardInputFile(shellFile);
myProcess->start(program);


--> No result. I can compile without problems, but when clicking the button nothing happens.

Furthermore I tried it with the system function (stdlib.h class):

1
2
3
QString File = MainFile + "/constant/polyMesh";
std::string File2 = File.toStdString();
system(File2.c_str());


--> result: when clicking the button I get the error message:

sh: /home/mathic/ert/constant/polyMesh: Permission denied

I guess I haven't the rights to execute the process in the second case, but I don't know how to handle this.

Can someone tell me how to execute the Shell Script? :)

greetings
outer


Last edited on
Assuming the file is yours, all (I think) you need to do is open a terminal and type this:
chmod +x yourfile
...where yourfile is... your file. This'll allow running of the file. Good luck! ;)

By the way... why are you mixing C++ and shell scripts? :/

-Albatross
Last edited on
I have written a GUI and now I have to start a Shell Script by using one button of the GUI. Therefore I mix c++ and shell scripts.

Another question:

Because the shellscript I want to run is always created new when using the GUI I need to change the standard file rights for new created files/directories. I know I have to change the file /etc/profile by using the terminal, but I don know how to do this. The file rights for new files are 0002 as standard (proofed with unmask), so I thought changing it to 0777 would be the best. Do you or does anybody know how to do this?
Wait wait wait. Your question is on how to ensure that the file you're creating will have permission to run, correct? If so, there there are a few C functions that could help you with that.

Here's a link to a documentation page on the sys/stat.h header. I think you'd be most interested in the chmod function listed there, near the bottom. :)
http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstat.h.html

At the end of the day, I doubt you'll have to mess around with anything in the /etc/ directory.

-Albatross
Last edited on
Thx for the answer - the given documentation is very interesting though I have to handle my source code now in another way, because my tutor wants so. Now I will have to run the ShellScript, not by running the ShellScript itself, but by running the commands of the ShellScript in my source code. But I'm already working on that.
Topic archived. No new replies allowed.