13 #ifndef __STOUT_OS_WINDOWS_SHELL_HPP__ 14 #define __STOUT_OS_WINDOWS_SHELL_HPP__ 17 #include <processthreadsapi.h> 49 constexpr
const char*
name =
"cmd.exe";
50 constexpr
const char*
arg0 =
"cmd.exe";
51 constexpr
const char*
arg1 =
"/c";
56 template <
typename... T>
80 const std::unique_ptr<wchar_t*, decltype(&::LocalFree)> argv(
81 ::CommandLineToArgvW(wide_stringify(command.
get()).data(), &argc),
83 if (argv ==
nullptr) {
87 for (
int i = 0; i < argc; ++i) {
88 args.push_back(
stringify(std::wstring(argv.get()[i])));
102 if (stdout_.isError()) {
103 return Error(stdout_.error());
107 if (stderr_.isError()) {
108 return Error(stderr_.error());
117 foreach (
int_fd& fd, fds) {
121 } closer = {{stdin_.
get(), stdout_.get()[0], stderr_.get()}};
123 array<int_fd, 3> pipes = {stdin_.
get(), stdout_.get()[1], stderr_.get()};
139 part =
os::read(stdout_.get()[0], 1024);
149 if (!::GetExitCodeProcess(
151 return Error(
"Failed to `GetExitCodeProcess`: " + command.
get());
159 "Failed to execute '" + command.
get() +
160 "'; the command was either " 161 "not found or exited with a non-zero exit status: " +
173 #endif // __STOUT_OS_WINDOWS_SHELL_HPP__ constexpr const char * arg1
Definition: shell.hpp:43
Try< std::array< int, 2 > > pipe()
Definition: pipe.hpp:33
Definition: errorbase.hpp:36
T & get()&
Definition: try.hpp:80
HANDLE get_handle() const
Definition: windows.hpp:90
Try< ProcessData > create_process(const std::string &command, const std::vector< std::string > &argv, const Option< std::map< std::string, std::string >> &environment, const bool create_suspended=false, const Option< std::array< int_fd, 3 >> &pipes=None(), const std::vector< int_fd > &whitelist_fds={})
Definition: exec.hpp:263
Try< int_fd > open(const std::string &path, int oflag, mode_t mode=0)
Definition: open.hpp:35
Result< ProcessStatus > status(pid_t pid)
Definition: proc.hpp:166
Definition: error.hpp:108
Definition: posix_signalhandler.hpp:23
SharedHandle process_handle
Definition: exec.hpp:223
constexpr const char * arg0
Definition: shell.hpp:42
Try< Nothing > close(int fd)
Definition: close.hpp:24
static Try error(const E &e)
Definition: try.hpp:43
Result< std::string > read(int_fd fd, size_t size)
Definition: read.hpp:55
Try< std::string > shell(const std::string &fmt, const T &...t)
Definition: shell.hpp:49
bool isError() const
Definition: try.hpp:78
T & get()&
Definition: result.hpp:116
constexpr char DEV_NULL[]
Definition: constants.hpp:30
bool isSome() const
Definition: result.hpp:112
Try< std::string > format(const std::string &s, const T &...t)
Definition: format.hpp:58
int int_fd
Definition: int_fd.hpp:35
std::string stringify(int flags)
Option< int > spawn(const std::string &file, const std::vector< std::string > &arguments)
Definition: exec.hpp:32
constexpr const char * name
Definition: shell.hpp:41
Option< int > system(const std::string &command)
Definition: shell.hpp:97