Core/Utilities: Fixed child process console output being incorrectly cut off at first newline

This commit is contained in:
Shauren
2022-03-09 16:22:04 +01:00
parent 209b90cfdd
commit a5f107dafc

View File

@@ -19,7 +19,6 @@
#include "Errors.h"
#include "Log.h"
#include "Optional.h"
#include "Util.h"
#include "Hacks/boost_1_73_process_windows_nopch.h"
@@ -54,10 +53,19 @@ public:
std::streamsize write(char const* str, std::streamsize size)
{
std::string consoleStr(str, size);
RemoveCRLF(consoleStr);
callback_(consoleStr);
return size;
std::string_view consoleStr(str, size);
size_t lineEnd = consoleStr.find_first_of("\r\n");
std::streamsize processedCharacters = size;
if (lineEnd != std::string_view::npos)
{
consoleStr = consoleStr.substr(0, lineEnd);
processedCharacters = lineEnd + 1;
}
if (!consoleStr.empty())
callback_(consoleStr);
return processedCharacters;
}
};
@@ -119,14 +127,14 @@ static int CreateChildProcess(T waiter, std::string const& executable,
}
}();
auto outInfo = MakeTCLogSink([&](std::string const& msg)
auto outInfo = MakeTCLogSink([&](std::string_view msg)
{
TC_LOG_INFO(logger, "%s", msg.c_str());
TC_LOG_INFO(logger, STRING_VIEW_FMT, STRING_VIEW_FMT_ARG(msg));
});
auto outError = MakeTCLogSink([&](std::string const& msg)
auto outError = MakeTCLogSink([&](std::string_view msg)
{
TC_LOG_ERROR(logger, "%s", msg.c_str());
TC_LOG_ERROR(logger, STRING_VIEW_FMT, STRING_VIEW_FMT_ARG(msg));
});
copy(outStream, outInfo);