MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / check_exec

Method check_exec

src/jit/impl/utils.cpp:69–89  ·  view source on GitHub ↗

execute command and check if exit code is zero

Source from the content-addressed store, hash-verified

67
68 //! execute command and check if exit code is zero
69 static void check_exec(const std::string& cmd) {
70#if MGB_ENABLE_DEBUG_UTIL
71 debug::ScopedForkWarningSupress no_fork_warning;
72#endif
73 std::string out;
74 std::array<char, 128> buffer;
75 FILE* pipe = popen((cmd + " 2>&1").c_str(), "r");
76 mgb_throw_if(
77 !pipe, SystemError, "popen() for cmd %s failed: %s", cmd.c_str(),
78 strerror(errno));
79 std::unique_ptr<FILE, int (*)(FILE*)> pipe_close{pipe, ::pclose};
80 while (fgets(buffer.data(), buffer.size(), pipe) != nullptr) {
81 out += buffer.data();
82 }
83 pipe_close.release();
84 int ret = pclose(pipe);
85 mgb_throw_if(
86 ret, SystemError,
87 "command %s failed: return code=%d; captured output:\n%s", cmd.c_str(),
88 ret, out.c_str());
89 }
90
91public:
92 ExecutableHelperImpl() {

Callers

nothing calls this directly

Calls 3

dataMethod · 0.45
sizeMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected