command.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #include <cstdint>
  2. #include <map>
  3. #include <iostream>
  4. #include <cstring>
  5. #include <cstdio>
  6. #include <string>
  7. #include <memory>
  8. #include "camera_log.h"
  9. class CommandExecutor
  10. {
  11. private:
  12. static std::string executeCommand(const std::string &command)
  13. {
  14. // 使用 popen 执行命令并捕获其输出
  15. std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(command.c_str(), "r"), pclose);
  16. if (!pipe)
  17. {
  18. IT3256_LOGI("it3256 Failed to execute command %{public}s", command.c_str());
  19. std::cerr << ": Failed to execute command: " << command << std::endl;
  20. return "-1";
  21. }
  22. // 读取命令的输出
  23. char buffer[128];
  24. std::string result;
  25. while (fgets(buffer, sizeof(buffer), pipe.get()) != nullptr)
  26. {
  27. result += buffer;
  28. }
  29. IT3256_LOGI("it3256 success to execute command %{public}s", result.c_str());
  30. return result;
  31. }
  32. public:
  33. static int getAIRange(unsigned char startChannel, unsigned char stopChannel, unsigned char *poutbuf);
  34. };