From 03490377113fe8910bab936cc6c3ca7b2e2d29d4 Mon Sep 17 00:00:00 2001 From: Martchus Date: Sat, 19 Aug 2023 00:11:06 +0200 Subject: [PATCH] Fix passing non-ASCII arguments in `execApp()` under Windows --- tests/testutils.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/testutils.cpp b/tests/testutils.cpp index 5dee94b..041b4c2 100644 --- a/tests/testutils.cpp +++ b/tests/testutils.cpp @@ -437,10 +437,23 @@ static int execAppInternal(const char *appPath, const char *const *args, std::st auto path = enableSearchPath ? boost::process::search_path(appPath) : boost::process::filesystem::path(appPath); auto ctx = boost::asio::io_context(); auto group = boost::process::group(); - auto argsAsVector = std::vector(); + auto argsAsVector = +#if defined(PLATFORM_WINDOWS) + std::vector(); +#else + std::vector(); +#endif if (*args) { for (const char *const *arg = args + 1; *arg; ++arg) { +#if defined(PLATFORM_WINDOWS) + auto ec = std::error_code(); + argsAsVector.emplace_back(convertMultiByteToWide(ec, std::string_view(*arg))); + if (ec) { + throw std::runtime_error(argsToString("unable to convert arg \"", *arg, "\" to wide string")); + } +#else argsAsVector.emplace_back(*arg); +#endif } } auto outputBuffer = boost::asio::streambuf(), errorBuffer = boost::asio::streambuf();