1#ifndef UVW_PROCESS_INCLUDE_H
2#define UVW_PROCESS_INCLUDE_H
20enum class uvw_process_flags : std::underlying_type_t<uv_process_flags> {
21 SETUID = UV_PROCESS_SETUID,
22 SETGID = UV_PROCESS_SETGID,
23 WINDOWS_VERBATIM_ARGUMENTS = UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS,
24 DETACHED = UV_PROCESS_DETACHED,
25 WINDOWS_HIDE = UV_PROCESS_WINDOWS_HIDE,
26 WINDOWS_HIDE_CONSOLE = UV_PROCESS_WINDOWS_HIDE_CONSOLE,
27 WINDOWS_HIDE_GUI = UV_PROCESS_WINDOWS_HIDE_GUI,
28 WINDOWS_FILE_PATH_EXACT_NAME = UV_PROCESS_WINDOWS_FILE_PATH_EXACT_NAME,
32enum class uvw_stdio_flags : std::underlying_type_t<uv_stdio_flags> {
33 IGNORE_STREAM = UV_IGNORE,
34 CREATE_PIPE = UV_CREATE_PIPE,
35 INHERIT_FD = UV_INHERIT_FD,
36 INHERIT_STREAM = UV_INHERIT_STREAM,
37 READABLE_PIPE = UV_READABLE_PIPE,
38 WRITABLE_PIPE = UV_WRITABLE_PIPE,
39 OVERLAPPED_PIPE = UV_OVERLAPPED_PIPE,
47 explicit exit_event(int64_t code,
int sig)
noexcept;
59class process_handle final:
public handle<process_handle, uv_process_t, exit_event> {
60 static void exit_callback(uv_process_t *hndl, int64_t exit_status,
int term_signal);
63 using process_flags = details::uvw_process_flags;
64 using stdio_flags = details::uvw_stdio_flags;
66 process_handle(loop::token token, std::shared_ptr<loop> ref);
90 static
bool kill(
int pid,
int signum) noexcept;
110 int spawn(const
char *file,
char **args,
char **env =
nullptr);
133 process_handle &
cwd(const std::
string &path) noexcept;
179 template<typename T, typename U, typename... E>
181 uv_stdio_container_t container;
182 container.flags =
static_cast<uv_stdio_flags
>(
flags);
183 container.data.stream =
reinterpret_cast<uv_stream_t *
>(stream.raw());
184 po_stream_stdio.push_back(std::move(container));
232 process_flags po_flags;
233 std::vector<uv_stdio_container_t> po_fd_stdio;
234 std::vector<uv_stdio_container_t> po_stream_stdio;
242# include "process.cpp"
os_file_descriptor fd() const
process_handle & stdio(file_handle fd, stdio_flags flags)
Makes a file descriptor available to the child process.
int init()
Initializes the handle.
process_handle & gid(gid_type id)
Sets the child process' group id.
int spawn(const char *file, char **args, char **env=nullptr)
spawn Starts the process.
process_handle & flags(process_flags flags) noexcept
Sets flags that control how spawn() behaves.
static bool kill(int pid, int signum) noexcept
kill Sends the specified signal to the given PID.
process_handle & uid(uid_type id)
Sets the child process' user id.
process_handle & stdio(stream_handle< T, U, E... > &stream, stdio_flags flags)
Makes a stdio handle available to the child process.
int pid() noexcept
Gets the PID of the spawned process.
process_handle & cwd(const std::string &path) noexcept
Sets the current working directory for the subprocess.
static void disable_stdio_inheritance() noexcept
Disables inheritance for file descriptors/handles.
details::uv_type_wrapper< uv_file > file_handle