C++启动.bat文件

发布时间 2023-09-27 11:18:47作者: 西北逍遥

在C++中启动一个.bat文件,你可以使用标准库中的system函数。这个函数可以让你在C++程序中执行外部命令。

#include <cstdlib>

int main() {
    // 在这里替换成你的.bat文件的路径
    const char* batchFilePath = "C:\\Path\\To\\Your\\BatchFile.bat";

    // 使用system函数执行.bat文件
    int result = system(batchFilePath);

    // 检查执行结果
    if (result == 0) {
        std::cout << "Batch file executed successfully." << std::endl;
    } else {
        std::cerr << "Failed to execute batch file." << std::endl;
    }

    return 0;
}
请确保将batchFilePath

 

 

 

#######################