Changed: Detect .bat file in launchProgram and adapt syntax of CreateProcess

This commit is contained in:
kervala 2016-02-02 19:49:37 +01:00
parent 47f4a5d501
commit 5c8e42734c
2 changed files with 19 additions and 4 deletions

View file

@ -732,7 +732,22 @@ bool launchProgram(const std::string &programName, const std::string &arguments,
SetEnvironmentVariable( SE_TRANSLATOR_IN_MAIN_MODULE, NULL );
}
BOOL res = CreateProcessA(programName.empty() ? NULL:programName.c_str(), (char*)arguments.c_str(), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
const char *sProgramName = programName.c_str();
std::string args;
// a .bat file must have first parameter to NULL and use 2nd parameter to pass filename
if (CFile::getExtension(programName) == "bat")
{
sProgramName = NULL;
args = "\"" + programName + "\" " + arguments;
}
else
{
args = arguments;
}
BOOL res = CreateProcessA(sProgramName, (char*)args.c_str(), NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
if (res)
{

View file

@ -938,14 +938,14 @@ void CPatchManager::executeBatchFile()
chmod(batchFilename.c_str(), S_IRWXU);
#endif
std::string cmdLine = "\"" + batchFilename + "\" " + LoginLogin + " " + LoginPassword;
std::string arguments = LoginLogin + " " + LoginPassword;
if (!r2Mode)
{
cmdLine += " " + toString(LoginShardId);
arguments += " " + toString(LoginShardId);
}
if (launchProgram("", cmdLine, false))
if (launchProgram(batchFilename, arguments, false))
{
exit(0);
}