From a5f107dafc0788d4f1a05a70854f1b4ae27c0b7b Mon Sep 17 00:00:00 2001 From: Shauren Date: Wed, 9 Mar 2022 16:22:04 +0100 Subject: Core/Utilities: Fixed child process console output being incorrectly cut off at first newline --- src/common/Utilities/StartProcess.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/common/Utilities/StartProcess.cpp') diff --git a/src/common/Utilities/StartProcess.cpp b/src/common/Utilities/StartProcess.cpp index 0665e2644bf..00e5bc0bfe7 100644 --- a/src/common/Utilities/StartProcess.cpp +++ b/src/common/Utilities/StartProcess.cpp @@ -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); -- cgit v1.2.3