18 #ifndef GZ_UTILS__SUBPROCESS_HH_
19 #define GZ_UTILS__SUBPROCESS_HH_
21 #include "detail/subprocess.h"
29 #include <gz/utils/detail/subprocess.h>
91 private:
void Create()
96 this->
process =
new subprocess_s;
102 for (
const auto &val : this->commandLine)
110 for (
const auto &val : environmentStr)
120 ret = subprocess_create_ex(commandLineCstr.
data(),
121 0, environmentCstr.
data(), this->process);
125 ret = subprocess_create(commandLineCstr.
data(),
126 subprocess_option_inherit_environment,
141 subprocess_destroy(this->
process);
150 auto *p_stdout = subprocess_stdout(this->
process);
152 while (!feof(p_stdout))
154 if (fgets(buffer, 128, p_stdout) !=
nullptr)
166 auto *p_stdout = subprocess_stderr(this->
process);
168 while (!feof(p_stdout))
170 if (fgets(buffer, 128, p_stdout) !=
nullptr)
181 return subprocess_alive(this->
process);
189 return subprocess_terminate(this->
process) != 0;
196 int return_code = -1;
199 auto ret = subprocess_join(this->
process, &return_code);