Changed: Check return code of WaitForSingleObject and log error
This commit is contained in:
parent
5a5bc16225
commit
d3b6102228
1 changed files with 21 additions and 9 deletions
|
@ -1012,8 +1012,10 @@ sint launchProgramAndWaitForResult(const std::string &programName, const std::st
|
||||||
if (!createProcess(programName, arguments, log, pi)) return -1;
|
if (!createProcess(programName, arguments, log, pi)) return -1;
|
||||||
|
|
||||||
// Successfully created the process. Wait for it to finish.
|
// Successfully created the process. Wait for it to finish.
|
||||||
WaitForSingleObject(pi.hProcess, INFINITE);
|
DWORD ret = WaitForSingleObject(pi.hProcess, INFINITE);
|
||||||
|
|
||||||
|
if (ret == WAIT_OBJECT_0)
|
||||||
|
{
|
||||||
// Get the exit code.
|
// Get the exit code.
|
||||||
DWORD exitCode = 0;
|
DWORD exitCode = 0;
|
||||||
BOOL ok = GetExitCodeProcess(pi.hProcess, &exitCode);
|
BOOL ok = GetExitCodeProcess(pi.hProcess, &exitCode);
|
||||||
|
@ -1023,9 +1025,19 @@ sint launchProgramAndWaitForResult(const std::string &programName, const std::st
|
||||||
CloseHandle(pi.hThread);
|
CloseHandle(pi.hThread);
|
||||||
|
|
||||||
if (ok) return (sint)exitCode;
|
if (ok) return (sint)exitCode;
|
||||||
|
}
|
||||||
|
|
||||||
if (log)
|
if (log)
|
||||||
nlwarning("LAUNCH: Failed launched '%s' with arg '%s'", programName.c_str(), arguments.c_str());
|
{
|
||||||
|
std::string error = toString((uint)ret);
|
||||||
|
|
||||||
|
if (ret == WAIT_FAILED)
|
||||||
|
{
|
||||||
|
error += "(" + formatErrorMessage(getLastError()) +")";
|
||||||
|
}
|
||||||
|
|
||||||
|
nlwarning("LAUNCH: Failed launched '%s' with arg '%s' and error: %s", programName.c_str(), arguments.c_str(), error.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in a new issue