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"
91 SDL_PROCESS_STDIO_INHERITED;
95 SDL_PROCESS_STDIO_NULL;
217 if (data.
empty())
return {};
218 size_t sz = data.
size() /
sizeof(T);
289 void Kill(
bool force);
321 bool Wait(
bool block,
int* exitcode);
335 using ProcessBase::ProcessBase;
394 Process(
const char*
const* args,
bool pipe_stdio);
520 return Process(args, pipe_stdio);
524 :
Process(SDL_CreateProcess(args, pipe_stdio))
529 :
Process(SDL_CreateProcessWithProperties(props))
615 SDL_PROP_PROCESS_CREATE_ARGS_POINTER;
618 SDL_PROP_PROCESS_CREATE_ENVIRONMENT_POINTER;
620#if SDL_VERSION_ATLEAST(3, 4, 0)
623 SDL_PROP_PROCESS_CREATE_WORKING_DIRECTORY_STRING;
629 SDL_PROP_PROCESS_CREATE_STDIN_NUMBER;
632 SDL_PROP_PROCESS_CREATE_STDIN_POINTER;
635 SDL_PROP_PROCESS_CREATE_STDOUT_NUMBER;
638 SDL_PROP_PROCESS_CREATE_STDOUT_POINTER;
641 SDL_PROP_PROCESS_CREATE_STDERR_NUMBER;
644 SDL_PROP_PROCESS_CREATE_STDERR_POINTER;
647 SDL_PROP_PROCESS_CREATE_STDERR_TO_STDOUT_BOOLEAN;
651 SDL_PROP_PROCESS_CREATE_BACKGROUND_BOOLEAN;
653#if SDL_VERSION_ATLEAST(3, 4, 0)
656 SDL_PROP_PROCESS_CREATE_CMDLINE_STRING;
693 return {
CheckError(SDL_GetProcessProperties(process))};
717 SDL_PROP_PROCESS_STDIN_POINTER;
720 SDL_PROP_PROCESS_STDOUT_POINTER;
723 SDL_PROP_PROCESS_STDERR_POINTER;
726 SDL_PROP_PROCESS_BACKGROUND_BOOLEAN;
760 auto data =
static_cast<char*
>(SDL_ReadProcess(process, &size, exitcode));
795 return {SDL_GetProcessInput(process)};
827 return {SDL_GetProcessOutput(process)};
894 return SDL_WaitProcess(process, block, exitcode);
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
T * release()
Release control on object.
Definition SDL3pp_ownPtr.h:91
constexpr bool empty() const
True if size() == 0.
Definition SDL3pp_ownPtr.h:74
constexpr size_t size() const
Size.
Definition SDL3pp_ownPtr.h:83
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
ResourceRefT< IOStreamBase > IOStreamRef
Reference for IOStream.
Definition SDL3pp_iostream.h:37
StringResult ReadProcess(ProcessRef process, int *exitcode=nullptr)
Read all the output from a process.
Definition SDL3pp_process.h:757
IOStreamRef GetInput()
Get the IOStream associated with process standard input.
Definition SDL3pp_process.h:798
SDL_ProcessIO ProcessIO
Description of where standard I/O should be directed when creating a process.
Definition SDL3pp_process.h:88
ResourceRefT< ProcessBase > ProcessRef
Reference for Process.
Definition SDL3pp_process.h:47
StringResult Read(int *exitcode=nullptr)
Read all the output from a process.
Definition SDL3pp_process.h:764
void Kill(bool force)
Stop a process.
Definition SDL3pp_process.h:859
IOStreamRef GetProcessOutput(ProcessRef process)
Get the IOStream associated with process standard output.
Definition SDL3pp_process.h:825
PropertiesRef GetProcessProperties(ProcessRef process)
Get the properties associated with a process.
Definition SDL3pp_process.h:691
Process CreateProcess(const char *const *args, bool pipe_stdio)
Create a new process.
Definition SDL3pp_process.h:518
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:101
PropertiesRef GetProperties() const
Get the properties associated with a process.
Definition SDL3pp_process.h:696
constexpr ProcessIO PROCESS_STDIO_NULL
The I/O stream is ignored.
Definition SDL3pp_process.h:94
void KillProcess(ProcessRef process, bool force)
Stop a process.
Definition SDL3pp_process.h:854
Process CreateProcessWithProperties(PropertiesRef props)
Create a new process with the specified properties.
Definition SDL3pp_process.h:602
bool WaitProcess(ProcessRef process, bool block, int *exitcode)
Wait for a process to finish.
Definition SDL3pp_process.h:892
void DestroyProcess(ProcessRaw process)
Destroy a previously created process object.
Definition SDL3pp_process.h:918
SDL_Process * ProcessRaw
Alias to raw representation for Process.
Definition SDL3pp_process.h:40
IOStreamRef GetProcessInput(ProcessRef process)
Get the IOStream associated with process standard input.
Definition SDL3pp_process.h:793
bool Wait(bool block, int *exitcode)
Wait for a process to finish.
Definition SDL3pp_process.h:897
constexpr ProcessIO PROCESS_STDIO_REDIRECT
The I/O stream is redirected to an existing IOStream.
Definition SDL3pp_process.h:104
constexpr ProcessIO PROCESS_STDIO_INHERITED
The I/O stream is inherited from the application.
Definition SDL3pp_process.h:90
IOStreamRef GetOutput()
Get the IOStream associated with process standard output.
Definition SDL3pp_process.h:830
void Destroy()
Destroy a previously created process object.
Definition SDL3pp_process.h:920
ResourceRefT< PropertiesBase > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:53
Properties for process creation.
Definition SDL3pp_process.h:612
constexpr auto CMDLINE_STRING
String for cmdline.
Definition SDL3pp_process.h:655
constexpr auto WORKING_DIRECTORY_STRING
String for working directory.
Definition SDL3pp_process.h:622
constexpr auto BACKGROUND_BOOLEAN
Enable background.
Definition SDL3pp_process.h:650
constexpr auto STDERR_NUMBER
Stderr number.
Definition SDL3pp_process.h:640
constexpr auto ENVIRONMENT_POINTER
Pointer to environment.
Definition SDL3pp_process.h:617
constexpr auto ARGS_POINTER
Pointer to args.
Definition SDL3pp_process.h:614
constexpr auto STDIN_POINTER
Pointer to stdin.
Definition SDL3pp_process.h:631
constexpr auto STDERR_TO_STDOUT_BOOLEAN
Enable stderr to stdout.
Definition SDL3pp_process.h:646
constexpr auto STDIN_NUMBER
Stdin number.
Definition SDL3pp_process.h:628
constexpr auto STDOUT_NUMBER
Stdout number.
Definition SDL3pp_process.h:634
constexpr auto STDOUT_POINTER
Pointer to stdout.
Definition SDL3pp_process.h:637
constexpr auto STDERR_POINTER
Pointer to stderr.
Definition SDL3pp_process.h:643
Properties for processes.
Definition SDL3pp_process.h:612
constexpr auto BACKGROUND_BOOLEAN
Background enabled.
Definition SDL3pp_process.h:725
constexpr auto STDOUT_POINTER
Pointer to stdout.
Definition SDL3pp_process.h:719
constexpr auto PID_NUMBER
Pid number.
Definition SDL3pp_process.h:714
constexpr auto STDIN_POINTER
Pointer to stdin.
Definition SDL3pp_process.h:716
constexpr auto STDERR_POINTER
Pointer to stderr.
Definition SDL3pp_process.h:722
Main include header for the SDL3pp library.
Base class to Process.
Definition SDL3pp_process.h:112
OwnArray< T > ReadAs(int *exitcode=nullptr)
Read all the output from a process.
Definition SDL3pp_process.h:214
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
An opaque handle representing a system process.
Definition SDL3pp_process.h:334
constexpr Process(Process &&other) noexcept
Move constructor.
Definition SDL3pp_process.h:350
constexpr Process & operator=(Process &&other) noexcept
Assignment operator.
Definition SDL3pp_process.h:472
~Process()
Destructor.
Definition SDL3pp_process.h:469
constexpr Process(ProcessRaw resource) noexcept
Constructs from raw Process.
Definition SDL3pp_process.h:344
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93
A simple std::string-like interface for SDL allocated strings.
Definition SDL3pp_strings.h:147