| 132 | } |
| 133 | |
| 134 | std::string queryCmd(std::string_view cmd, int* status) |
| 135 | { |
| 136 | std::string outputstr; |
| 137 | std::string cmd_str(cmd); // Convert string_view to std::string for popen |
| 138 | FILE *output = popen(cmd_str.c_str(), "r"); |
| 139 | if (output != NULL) { |
| 140 | char buf[256]; |
| 141 | if (fgets(buf, 256, output) != 0) { |
| 142 | outputstr = buf; |
| 143 | } |
| 144 | int s = pclose(output); |
| 145 | if (status) *status = s; |
| 146 | } |
| 147 | |
| 148 | /* Trim the value */ |
| 149 | size_t end = outputstr.find_last_not_of(" \n\r\t\f\v"); |
| 150 | outputstr = (end == std::string::npos) ? "" : outputstr.substr(0, end + 1); |
| 151 | return outputstr; |
| 152 | } |
| 153 | |
| 154 | std::string queryCmdPid(const char **command, pid_t* popen_pid) |
| 155 | { |
no test coverage detected