b
This commit is contained in:
+18
-2
@@ -1,13 +1,27 @@
|
|||||||
#include "process_.h"
|
#include "process_.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <cstddef>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace anm2ed::util
|
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(const char* command, const char* mode) { open(command, mode); }
|
||||||
|
|
||||||
Process::~Process() { close(); }
|
Process::~Process() { close(); }
|
||||||
@@ -17,7 +31,9 @@ namespace anm2ed::util
|
|||||||
close();
|
close();
|
||||||
|
|
||||||
#ifdef WIN32
|
#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
|
#else
|
||||||
pipe = popen(command, mode);
|
pipe = popen(command, mode);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user