tags:

views:

240

answers:

5

Hello MY PURPOSE: i want to make a c++ program that could use dos commands. OPTION: i can make a batch file and put into it the dos commands. but how to use this file from c++ program...?

+4  A: 

You probably want to look at the system, ShellExecute, and CreateProcess calls, to figure out which one is appropriate in this scenario.

Novelocrat
+2  A: 
system("mybatchfile.bat");

system() reference

luke
A: 

You can use system call in c++ program to execute all the commands that C++ program gets from the user.

VNarasimhaM
+4  A: 

There are two options available to run batch files on Windows from C/C++.

First, you can use system (or _wsystem for wide characters).

"The system function passes command to the command interpreter, which executes the string as an operating-system command. system refers to the COMSPEC and PATH environment variables that locate the command-interpreter file (the file named CMD.EXE in Windows 2000 and later)."

Or you can use CreateProcess directly.

Note that for batch files:

"To run a batch file, you must start the command interpreter; set lpApplicationName to cmd.exe and set lpCommandLine to the following arguments: /c plus the name of the batch file."

Todd
A: 

I TRIED THIS SYSTEM() CALL IT DOES NOT GIVE ANY ERROR BUT NOT ALSO THE OTPUT.

INCLUDE

INCLUDE

INCLUDE

VOID MAIN() { SYSTEM("DATE"); GETCHE(); } (I WROTE THE CODE ABOVE IN SMALL CASE LETTERS)

Rahul
As a next step, try adding some lower case letters not only to your code but to your question! Brings great happiness, I promise :-). Also, similar question: http://stackoverflow.com/questions/125828
Chris