| 22 | #include <stdlib.h> |
| 23 | |
| 24 | bool popen_test(const std::string& cmd, int expect = 0) { |
| 25 | puts(cmd.c_str()); |
| 26 | auto p = popen(cmd.c_str(), "r"); |
| 27 | char buffer[4096]; |
| 28 | while (fgets(buffer, sizeof(buffer), p) != NULL) |
| 29 | ; |
| 30 | auto r = pclose(p); |
| 31 | if (WIFEXITED(r)) return WEXITSTATUS(r) == expect; |
| 32 | puts("Not exit"); |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | std::string popen_read(const std::string& cmd, int expect = 0) { |
| 37 | std::string ret; |