diff --git a/src/util/process_.cpp b/src/util/process_.cpp index dbe2984..fa4cfe3 100644 --- a/src/util/process_.cpp +++ b/src/util/process_.cpp @@ -1,13 +1,27 @@ #include "process_.h" #ifdef WIN32 - #include #include #include #endif namespace anm2ed::util { +#ifdef WIN32 + namespace + { + std::wstring utf8_to_wstring(const char* text) + { + if (!text) return {}; + auto sizeRequired = MultiByteToWideChar(CP_UTF8, 0, text, -1, nullptr, 0); + if (sizeRequired <= 0) return {}; + std::wstring wide(static_cast(sizeRequired - 1), L'\0'); + MultiByteToWideChar(CP_UTF8, 0, text, -1, wide.data(), sizeRequired); + return wide; + } + } +#endif + Process::Process(const char* command, const char* mode) { open(command, mode); } Process::~Process() { close(); } @@ -17,7 +31,9 @@ namespace anm2ed::util close(); #ifdef WIN32 - pipe = _popen(command, mode); + auto wideCommand = utf8_to_wstring(command); + auto wideMode = utf8_to_wstring(mode); + pipe = _wpopen(wideCommand.c_str(), wideMode.c_str()); #else pipe = popen(command, mode); #endif