user19596744
user19596744

Reputation:

how to use batch in c++

I have a batch program that I would like to add to one of my c++ programs. The batch program tests if a file exists and exits the script if it doesn't. I do not want to add any more libraries to my code. The problem that I have is that I am not sure how I am able to use batch in c++. I am able to figure everything else out on my own I just need to know this one thing.

Upvotes: 1

Views: 613

Answers (2)

samnoon
samnoon

Reputation: 1743

Assuming you are on Windows, you have two options available to run batch files on Windows from C/C++.

  • 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

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."

Upvotes: 0

NotePro.bat
NotePro.bat

Reputation: 86

You can use the system(" ") command to use batch.

Upvotes: 2

Related Questions