diff options
author | Shauren <shauren.trinity@gmail.com> | 2022-03-09 16:22:04 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2022-03-09 16:22:40 +0100 |
commit | 53e1666a93d4d4d595b8707a39a88395030108ae (patch) | |
tree | a4be6fe22474c510d7fad07870e575a6f94bcb36 | |
parent | 77b9afdfc086bc02b5a646591f4483f09f62d78d (diff) |
Core/Utilities: Fixed child process console output being incorrectly cut off at first newline
(cherry picked from commit a5f107dafc0788d4f1a05a70854f1b4ae27c0b7b)
-rw-r--r-- | src/common/Utilities/StartProcess.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
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); |