Run an external command and return its standard output.
| 198 | |
| 199 | // Run an external command and return its standard output. |
| 200 | static std::string RunCommand(std::string cmd) { |
| 201 | std::ostringstream ret; |
| 202 | |
| 203 | FILE *proc = popen(cmd.c_str(), "r"); |
| 204 | if (proc) { |
| 205 | while (!feof(proc)) { |
| 206 | char buf[PIPE_BUF]; |
| 207 | size_t bytes = fread(buf, 1, sizeof(buf), proc); |
| 208 | ret.write(buf, bytes); |
| 209 | } |
| 210 | pclose(proc); |
| 211 | } |
| 212 | |
| 213 | return ret.str(); |
| 214 | } |
| 215 | |
| 216 | // If mmap is used (as for shared objects), code address at runtime can be |
| 217 | // arbitrary. This function translates an absolute address into a relative |