13 #ifndef __STOUT_OS_POSIX_SHELL_HPP__ 14 #define __STOUT_OS_POSIX_SHELL_HPP__ 24 #include <glog/logging.h> 41 constexpr
const char*
name =
"sh";
42 constexpr
const char*
arg0 =
"sh";
43 constexpr
const char*
arg1 =
"-c";
48 template <
typename... T>
57 std::ostringstream stdout;
59 if ((file = popen(command->c_str(),
"r")) ==
nullptr) {
60 return Error(
"Failed to run '" + command.
get() +
"'");
66 while (fgets(line,
sizeof(line), file) !=
nullptr) {
70 if (ferror(file) != 0) {
72 return Error(
"Error reading output of '" + command.
get() +
"'");
76 if ((status = pclose(file)) == -1) {
77 return Error(
"Failed to get status of '" + command.
get() +
"'");
82 "Running '" + command.
get() +
"' was interrupted by signal '" +
85 LOG(ERROR) <<
"Command '" << command.
get()
86 <<
"' failed; this is the output:\n" << stdout.str();
88 "Failed to execute '" + command.
get() +
"'; the command was either " 89 "not found or exited with a non-zero exit status: " +
102 }
else if (pid == 0) {
110 while (::
waitpid(pid, &status, 0) == -1) {
111 if (errno != EINTR) {
122 #endif // __STOUT_OS_POSIX_SHELL_HPP__ constexpr const char * arg1
Definition: shell.hpp:43
Definition: errorbase.hpp:36
T & get()&
Definition: try.hpp:80
const char * strsignal(int signum)
Definition: windows.hpp:347
Result< ProcessStatus > status(pid_t pid)
Definition: proc.hpp:166
Definition: posix_signalhandler.hpp:23
constexpr const char * arg0
Definition: shell.hpp:42
DWORD pid_t
Definition: windows.hpp:181
URI file(const std::string &path)
Creates a file URI with the given path on the local host.
Definition: file.hpp:33
#define WIFSIGNALED(x)
Definition: windows.hpp:376
Result< pid_t > waitpid(pid_t pid, int *status, int options)
Definition: os.hpp:141
#define WEXITSTATUS(x)
Definition: windows.hpp:368
static Try error(const E &e)
Definition: try.hpp:43
Try< std::string > shell(const std::string &fmt, const T &...t)
Definition: shell.hpp:49
bool isError() const
Definition: try.hpp:78
Try< std::string > format(const std::string &s, const T &...t)
Definition: format.hpp:58
std::string stringify(int flags)
constexpr const char * name
Definition: shell.hpp:41
Option< int > system(const std::string &command)
Definition: shell.hpp:97