From 121747352d59b7df0a24d549f2d740b71bf80f05 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Mon, 3 Feb 2020 16:35:30 +0100 Subject: [PATCH] buffer --- slsDetectorSoftware/src/DetectorImpl.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 183f41547..9adaff1f0 100755 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -294,23 +294,19 @@ bool DetectorImpl::isAcquireReady() { } std::string DetectorImpl::exec(const char *cmd) { - int bufsize = 128; - char buffer[bufsize]; - std::string result = ""; + char buffer[128]; + std::string result; FILE *pipe = popen(cmd, "r"); if (pipe == nullptr) { throw RuntimeError("Could not open pipe"); } - try { - while (feof(pipe) == 0) { - if (fgets(buffer, bufsize, pipe) != nullptr) { - result += buffer; - } + + while (feof(pipe) == 0) { + if (fgets(buffer, sizeof(buffer), pipe) != nullptr) { + result += buffer; } - } catch (...) { - pclose(pipe); - throw; } + pclose(pipe); result.erase(result.find_last_not_of(" \t\n\r") + 1); return result;