Running an External Program

Running an External Program

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

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.

See also  5 Strategies for Supercharging Your CRM

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist