| 55 | |
| 56 | template <class F> |
| 57 | static int exec(const std::string& cmd, const char* type, F f) |
| 58 | { |
| 59 | int ec = 0; |
| 60 | if(enabled(MIGRAPHX_TRACE_CMD_EXECUTE{})) |
| 61 | std::cout << cmd << std::endl; |
| 62 | auto closer = [&](FILE* stream) { |
| 63 | auto status = pclose(stream); |
| 64 | ec = WIFEXITED(status) ? WEXITSTATUS(status) : 0; // NOLINT |
| 65 | }; |
| 66 | { |
| 67 | // TODO: Use execve instead of popen |
| 68 | std::unique_ptr<FILE, decltype(closer)> pipe(popen(cmd.c_str(), type), closer); // NOLINT |
| 69 | if(not pipe) |
| 70 | MIGRAPHX_THROW("popen() failed: " + cmd); |
| 71 | f(pipe.get()); |
| 72 | } |
| 73 | return ec; |
| 74 | } |
| 75 | |
| 76 | static int exec(const std::string& cmd, const std::function<void(const char*)>& std_out) |
| 77 | { |
no test coverage detected