Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: Beginner
Feb 29, 2000

Running an External Program

Question:
How do you get C++ to run an outside program? How do you type this in the source code?

Answer:
You can invoke another executable from your programming by calling the system() function (defined in ). System() takes a const char * that is the name of an .exe or .bat file and passes it to the shell command, which in turn, invokes that program.

For example, if you have an executable called "calculator.exe" and you want to run this program from your application:

#include 
int main()
{
  system("calculator.exe");
}

Many platforms have other functions that launch a program, e.g., execvp(). However, system() is portable because it's defined by the ANSI C and C++ standards.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date