LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Running shell script within a C or C++ program (http://www.linuxquestions.org/questions/programming-9/running-shell-script-within-a-c-or-c-program-333317/)

Quantum0726 06-14-2005 12:30 AM

Running shell script within a C or C++ program
 
Hi, I have a shell script that I'd like to execute from within a C++ program. For example, I need to access the man command, the redirection operator, and a command that converts a ps file to a pdf. If I can run my bash script from within a C++ binary this would take care of it. So would running each command from within the C++ program. I could also probably do this in C, but I'm not as familiar with C as I am with C++.

Thanks much!

uman 06-14-2005 12:42 AM

Make sure you've included cstdlib.

then do this:

system("name-of-command");

if your batch file is in the path you can do

system("name-of-your-batch-file");

system(const char*); basically runs an executable.

Quantum0726 06-15-2005 09:14 PM

Thanks, that worked great!


All times are GMT -5. The time now is 08:29 PM.