szaszm commented on code in PR #2008:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2008#discussion_r2282698741


##########
extensions/python/PythonDependencyInstaller.cpp:
##########
@@ -49,6 +51,39 @@ std::string encapsulateCommandInQuotesIfNeeded(const 
std::string& command) {
 #endif
 }
 
+#ifdef WIN32
+#define popen _popen
+#define pclose _pclose
+#endif
+
+std::pair<int, std::string> executeProcess(const std::string& command) {
+  std::array<char, 256> buffer{};
+
+  FILE* pipe = popen(encapsulateCommandInQuotesIfNeeded(command).c_str(), "r");
+  if (!pipe) {
+    return {1, fmt::format("Failed to open pipe for command: {}", command)};
+  }
+
+  std::string result;
+  while (fgets(buffer.data(), gsl::narrow<int>(buffer.size()), pipe) != 
nullptr) {
+    result += buffer.data();
+  }

Review Comment:
   An ostringstream would fit this problem better.



##########
extensions/python/PythonDependencyInstaller.cpp:
##########
@@ -49,6 +51,39 @@ std::string encapsulateCommandInQuotesIfNeeded(const 
std::string& command) {
 #endif
 }
 
+#ifdef WIN32
+#define popen _popen
+#define pclose _pclose
+#endif
+
+std::pair<int, std::string> executeProcess(const std::string& command) {

Review Comment:
   For the return type, I'd use an aggregate struct instead.



##########
extensions/python/PythonDependencyInstaller.cpp:
##########
@@ -49,6 +51,39 @@ std::string encapsulateCommandInQuotesIfNeeded(const 
std::string& command) {
 #endif
 }
 
+#ifdef WIN32
+#define popen _popen
+#define pclose _pclose
+#endif
+
+std::pair<int, std::string> executeProcess(const std::string& command) {
+  std::array<char, 256> buffer{};

Review Comment:
   At the very least I'd increase the buffer size, and use the common buffer 
size constant.
   ```suggestion
     std::array<char, utils::configuration::DEFAULT_BUFFER_SIZE> buffer{};
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to