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.
CodePudding user response:
You can use the system(" ")
command to use batch.
CodePudding user response:
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
- 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."