|
-
August 22nd, 2007, 01:04 PM
#1
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?
-
August 22nd, 2007, 03:07 PM
#2
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.
I owe Paul McKenzie a pizza.
I am no expert; but they say I can make concepts easy to understand. That's why newbies questions are mine!!! XD
-
August 22nd, 2007, 11:23 PM
#3
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.
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|