diff --git a/es-core/src/platform.cpp b/es-core/src/platform.cpp index 81262310b7..e65176de4c 100644 --- a/es-core/src/platform.cpp +++ b/es-core/src/platform.cpp @@ -2,7 +2,9 @@ #include #ifdef WIN32 -#include +#include +#include "Shlwapi.h" +#pragma comment(lib, "Shlwapi.lib") #else #include #endif @@ -31,12 +33,24 @@ int runRestartCommand() int runSystemCommand(const std::string& cmd_utf8) { #ifdef WIN32 - // on Windows we use _wsystem to support non-ASCII paths - // which requires converting from utf8 to a wstring - typedef std::codecvt_utf8 convert_type; - std::wstring_convert converter; - std::wstring wchar_str = converter.from_bytes(cmd_utf8); - return _wsystem(wchar_str.c_str()); + std::string args = std::string(PathGetArgs(cmd_utf8.c_str())); + std::string program = cmd_utf8.substr(0, cmd_utf8.length() - args.length()); + SHELLEXECUTEINFO ShExecInfo = {0}; + ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); + ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; + ShExecInfo.hwnd = NULL; + ShExecInfo.lpVerb = NULL; + ShExecInfo.lpFile = program.c_str(); + ShExecInfo.lpParameters = args.c_str(); + ShExecInfo.lpDirectory = NULL; + ShExecInfo.nShow = SW_SHOW; + ShExecInfo.hInstApp = NULL; + ShellExecuteEx(&ShExecInfo); + WaitForSingleObject(ShExecInfo.hProcess, INFINITE); + CloseHandle(ShExecInfo.hProcess); + DWORD dwExitCode = 0; + GetExitCodeProcess(ShExecInfo.hProcess, &dwExitCode); + return dwExitCode; #else return system(cmd_utf8.c_str()); #endif