How to run a bash script from C++ program


Question

Bash scripts are very useful and can save a lot of programming time. So how do you start a bash script in a C++ program? Also if you know how to make user become the super-user that would be nice also. Thanks!

1
46
3/14/2009 4:47:15 PM

Accepted Answer

Use the system function.

system("myfile.sh"); // myfile.sh should be chmod +x
61
3/14/2009 4:45:32 PM

#include <stdio.h>
#include <stdlib.h>

// ....


system("my_bash_script.sh");

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon