run programs from command prompt
Is there a way to run programs from C++ so that it executes a command in a linux command prompt?
say I wanted to execute several lines of code in the linux command prompt:
> myprogram.exe
> dot -o run.jpg run.dot
> xemacs file.cc
> ...etc...
and I wanted to do these hypothetical commands by running a C++ file:
> g++ -o runthis.exe runthis.cc
> runthis.exe
What is the syntax that I should use to be able to do this? And is there a way?
Re: run programs from command prompt
You can use the system(char *str) function, which executes the string pointed to by str as if it was typed at the command prompt. Be careful using this as it is a potential source of security holes (the classic check that you don't accidentally feed it "rm -f *").
For what you want to do, though, I'd suggest you to use a shell script.
Re: run programs from command prompt
Best way to implement such applications is using shell scripting or Perl as Sk# suggested. Using C++ is an overkill if you are not targetting anything else.