How to open Cmd (Command Prompt) using C program

Actually, I want to execute the DOS command using a C program and want to display the output of the DOS command in my C output window.

example:

use "dir C: \" which displays the output in the C-program

+7
source share
3 answers

To execute the command in the same cmd.exe window where your C program is running:

 #include <stdlib.h> . . . system("dir C:\\"); 

To start separate windows, you need to call cmd.exe :

 system("cmd.exe /c dir c:\\"); 

(Note: I have not tested this);

+9
source
 system("dir"); 

should reset in current stdout

+4
source

But system () is evil. Here's why: http://www.cplusplus.com/forum/articles/11153/ Before you use it, be sure to think about it.

+4
source

All Articles