b
This commit is contained in:
@@ -1,13 +1,27 @@
|
||||
#include "process_.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <windows.h>
|
||||
#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<std::size_t>(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
|
||||
|
||||
Reference in New Issue
Block a user