1#ifndef SDL3PP_PROCESS_H_
2#define SDL3PP_PROCESS_H_
4#include <SDL3/SDL_process.h>
5#include "SDL3pp_iostream.h"
6#include "SDL3pp_properties.h"
7#include "SDL3pp_stdinc.h"
104 SDL_PROCESS_STDIO_INHERITED;
108 SDL_PROCESS_STDIO_NULL;
196 auto data =
static_cast<char*
>(SDL_ReadProcess(
get(), &size, exitcode));
228 if (data.
empty())
return {};
229 size_t sz = data.
size() /
sizeof(T);
332 bool Wait(
bool block,
int* exitcode)
334 return SDL_WaitProcess(
get(), block, exitcode);
354 static void reset(SDL_Process* resource) { SDL_DestroyProcess(resource); }
410 return Process(SDL_CreateProcess(args, pipe_stdio));
476 return Process(SDL_CreateProcessWithProperties(props));
531namespace prop::process {
533constexpr auto CREATE_ARGS_POINTER = SDL_PROP_PROCESS_CREATE_ARGS_POINTER;
535constexpr auto CREATE_ENVIRONMENT_POINTER =
536 SDL_PROP_PROCESS_CREATE_ENVIRONMENT_POINTER;
538constexpr auto CREATE_STDIN_NUMBER = SDL_PROP_PROCESS_CREATE_STDIN_NUMBER;
540constexpr auto CREATE_STDIN_POINTER = SDL_PROP_PROCESS_CREATE_STDIN_POINTER;
542constexpr auto CREATE_STDOUT_NUMBER = SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER;
544constexpr auto CREATE_STDOUT_POINTER = SDL_PROP_PROCESS_CREATE_STDOUT_POINTER;
546constexpr auto CREATE_STDERR_NUMBER = SDL_PROP_PROCESS_CREATE_STDERR_NUMBER;
548constexpr auto CREATE_STDERR_POINTER = SDL_PROP_PROCESS_CREATE_STDERR_POINTER;
550constexpr auto CREATE_STDERR_TO_STDOUT_BOOLEAN =
551 SDL_PROP_PROCESS_CREATE_STDERR_TO_STDOUT_BOOLEAN;
553constexpr auto CREATE_BACKGROUND_BOOLEAN =
554 SDL_PROP_PROCESS_CREATE_BACKGROUND_BOOLEAN;
556constexpr auto PID_NUMBER = SDL_PROP_PROCESS_PID_NUMBER;
558constexpr auto STDIN_POINTER = SDL_PROP_PROCESS_STDIN_POINTER;
560constexpr auto STDOUT_POINTER = SDL_PROP_PROCESS_STDOUT_POINTER;
562constexpr auto STDERR_POINTER = SDL_PROP_PROCESS_STDERR_POINTER;
564constexpr auto BACKGROUND_BOOLEAN = SDL_PROP_PROCESS_BACKGROUND_BOOLEAN;
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:43
constexpr bool empty() const
True if size() == 0.
Definition SDL3pp_ownPtr.h:70
T * release()
Release control on object.
Definition SDL3pp_ownPtr.h:87
constexpr size_t size() const
Size.
Definition SDL3pp_ownPtr.h:79
RESOURCE release()
Returns reference and reset this.
Definition SDL3pp_resource.h:178
Implement shared ownership for a resource.
Definition SDL3pp_resource.h:283
Implement unique ownership for a resource.
Definition SDL3pp_resource.h:226
constexpr ResourceUnique(std::nullptr_t=nullptr)
Default constructor.
Definition SDL3pp_resource.h:231
void reset()
Resets the value, destroying the resource if not nullptr.
Definition SDL3pp_resource.h:265
A dumb pointer to resource.
Definition SDL3pp_resource.h:197
constexpr ResourceUnsafe()=default
Default constructor.
Implement weak ownership for a resource.
Definition SDL3pp_resource.h:328
A SDL managed resource.
Definition SDL3pp_resource.h:29
constexpr Resource(T resource={})
Constructs from the underlying resource.
Definition SDL3pp_resource.h:37
constexpr SDL_Process * get() const
Return contained resource;.
Definition SDL3pp_resource.h:76
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
SDL_ProcessIO ProcessIO
Description of where standard I/O should be directed when creating a process.
Definition SDL3pp_process.h:101
constexpr ProcessIO PROCESS_STDIO_APP
The I/O stream is connected to a new IOStream that the application can read or write.
Definition SDL3pp_process.h:114
ResourceShared< Process > ProcessShared
Handle to a shared process.
Definition SDL3pp_process.h:48
constexpr ProcessIO PROCESS_STDIO_NULL
The I/O stream is ignored.
Definition SDL3pp_process.h:107
ProcessShared share()
Move this process into a ProcessShared.
Definition SDL3pp_process.h:504
constexpr ProcessIO PROCESS_STDIO_REDIRECT
The I/O stream is redirected to an existing IOStream.
Definition SDL3pp_process.h:119
constexpr ProcessIO PROCESS_STDIO_INHERITED
The I/O stream is inherited from the application.
Definition SDL3pp_process.h:103
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
The read/write operation structure.
Definition SDL3pp_iostream.h:123
An opaque handle representing a system process.
Definition SDL3pp_process.h:132
IOStreamRef GetOutput()
Get the IOStreamRef associated with process standard output.
Definition SDL3pp_process.h:279
StringResult Read(int *exitcode=nullptr)
Read all the output from a process.
Definition SDL3pp_process.h:193
IOStreamRef GetInput()
Get the IOStreamRef associated with process standard input.
Definition SDL3pp_process.h:256
static void reset(SDL_Process *resource)
Destroy a previously created process object.
Definition SDL3pp_process.h:354
void Kill(bool force)
Stop a process.
Definition SDL3pp_process.h:300
PropertiesRef GetProperties() const
Get the properties associated with a process.
Definition SDL3pp_process.h:163
OwnArray< T > ReadAs(int *exitcode=nullptr)
Read all the output from a process.
Definition SDL3pp_process.h:225
bool Wait(bool block, int *exitcode)
Wait for a process to finish.
Definition SDL3pp_process.h:332
Unsafe Handle to process.
Definition SDL3pp_process.h:519
constexpr ProcessUnsafe(Process &&other)
Constructs ProcessUnsafe from Process.
Definition SDL3pp_process.h:525
Handle to an owned process.
Definition SDL3pp_process.h:365
void Destroy()
Destroy a previously created process object.
Definition SDL3pp_process.h:495
static Process CreateWithProperties(PropertiesRef props)
Create a new process with the specified properties.
Definition SDL3pp_process.h:474
static Process Create(const char *const *args, bool pipe_stdio)
Create a new process.
Definition SDL3pp_process.h:408
SDL properties ID.
Definition SDL3pp_properties.h:209
A simple std::string-like interface for SDL allocated strings.
Definition SDL3pp_strings.h:153