| 99 | } |
| 100 | |
| 101 | bool ExecuteShellCmd(const std::string& cmd, std::string* ret_str) { |
| 102 | char output_buffer[80]; |
| 103 | FILE* fp = popen(cmd.c_str(), "r"); |
| 104 | if (!fp) { |
| 105 | LOG(ERROR) << "fail to execute cmd: " << cmd; |
| 106 | return false; |
| 107 | } |
| 108 | fgets(output_buffer, sizeof(output_buffer), fp); |
| 109 | pclose(fp); |
| 110 | if (ret_str) { |
| 111 | *ret_str = std::string(output_buffer); |
| 112 | } |
| 113 | return true; |
| 114 | } |
| 115 | |
| 116 | std::string GetLocalHostAddr() { |
| 117 | std::string cmd = |