how can we use a batch file in c++?

前端 未结 6 2159
一整个雨季
一整个雨季 2020-12-15 09:36

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 I don\'t know how

6条回答
  •  春和景丽
    2020-12-15 10:10

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

提交回复
热议问题