#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
bool RunBatFile(char* batFileName)
{
char CurDir[MAX_PATH] = { 0 };
char BatFilePath[MAX_PATH] = { 0 };
GetModuleFileNameA(NULL, CurDir, sizeof(CurDir));
::PathRemoveFileSpecA(CurDir);
sprintf_s(BatFilePath, sizeof(BatFilePath), ("%s\\%s"), CurDir, batFileName);
// ShellExecuteA(NULL, "open", BatFilePath, "", NULL, SW_SHOW); // 可以直接执行该语句,下面的代码就不需要了
std::ifstream batFile;
batFile.open(BatFilePath);
if (!batFile.is_open())
{
cout << "Open bat file fail...";
return false;
}
std::string strTempCmd("");
while (getline(batFile, strTempCmd))
{
if ("PAUSE" == strTempCmd)
{
break;
}
cout << "Command is: " << strTempCmd << endl;
}
batFile.close();
return true;
}