John John - 1 year ago 158
C++ Question

Execute CMD commands using C++

In my project I want to execute some CMD commands. What is the syntax for doing that using C++.

Answer Source

You can execute Windows Command prompt commands using a C++ function called system();. For safer standards you are recommended to use Windows specific API'S like Use Windows specific APIs like ShellExecute or ShellExecuteEx. Here is how to run CMD command using system() function.

You should place the CMD command like shown below in the program source code:


Here is a program which executes the DATE command in CMD to find the date:

#include <iostream>
using namespace std;

int main() {
    return 0;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download