glibmm 2.80.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gio::Subprocess Class Reference

Child processes. More...

#include <giomm/subprocess.h>

Inheritance diagram for Gio::Subprocess:
Inheritance graph
[legend]

Public Types

enum class  Flags {
  Flags::NONE = 0x0 ,
  Flags::STDIN_PIPE = (1u << 0) ,
  Flags::STDIN_INHERIT = (1u << 1) ,
  Flags::STDOUT_PIPE = (1u << 2) ,
  Flags::STDOUT_SILENCE = (1u << 3) ,
  Flags::STDERR_PIPE = (1u << 4) ,
  Flags::STDERR_SILENCE = (1u << 5) ,
  Flags::STDERR_MERGE = (1u << 6) ,
  Flags::INHERIT_FDS = (1u << 7) ,
  Flags::SEARCH_PATH_FROM_ENVP = (1u << 8)
}
 Flags to define the behaviour of a Subprocess. More...
 
- Public Types inherited from Glib::Object
using DestroyNotify = void(*)(gpointer data)
 

Public Member Functions

 Subprocess (Subprocess && src) noexcept
 
Subprocessoperator= (Subprocess && src) noexcept
 
 ~Subprocess () noexcept override
 
GSubprocess * gobj ()
 Provides access to the underlying C GObject. More...
 
const GSubprocess * gobj () const
 Provides access to the underlying C GObject. More...
 
GSubprocess * gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
 
Glib::RefPtr< OutputStreamget_stdin_pipe ()
 Gets the OutputStream that you can write to in order to give data to the stdin of subprocess. More...
 
Glib::RefPtr< const OutputStreamget_stdin_pipe () const
 Gets the OutputStream that you can write to in order to give data to the stdin of subprocess. More...
 
Glib::RefPtr< InputStreamget_stdout_pipe ()
 Gets the InputStream from which to read the stdout output of subprocess. More...
 
Glib::RefPtr< const InputStreamget_stdout_pipe () const
 Gets the InputStream from which to read the stdout output of subprocess. More...
 
Glib::RefPtr< InputStreamget_stderr_pipe ()
 Gets the InputStream from which to read the stderr output of subprocess. More...
 
Glib::RefPtr< const InputStreamget_stderr_pipe () const
 Gets the InputStream from which to read the stderr output of subprocess. More...
 
Glib::ustring get_identifier () const
 On UNIX, returns the process ID as a decimal string. More...
 
void send_signal (int signal_num)
 Sends the UNIX signal signal_num to the subprocess, if it is still running. More...
 
void force_exit ()
 Use an operating-system specific method to attempt an immediate, forceful termination of the process. More...
 
void wait (const Glib::RefPtr< Cancellable > & cancellable={}) const
 Synchronously wait for the subprocess to terminate. More...
 
void wait_async (const SlotAsyncReady & slot, const Glib::RefPtr< Cancellable > & cancellable={}) const
 Wait for the subprocess to terminate. More...
 
void wait_finish (const Glib::RefPtr< AsyncResult > & result) const
 Collects the result of a previous call to g_subprocess_wait_async(). More...
 
void wait_check (const Glib::RefPtr< Cancellable > & cancellable={}) const
 Combines g_subprocess_wait() with Glib::spawn_check_wait_status(). More...
 
void wait_check_async (const SlotAsyncReady & slot, const Glib::RefPtr< Cancellable > & cancellable={}) const
 Combines g_subprocess_wait_async() with Glib::spawn_check_wait_status(). More...
 
void wait_check_finish (const Glib::RefPtr< AsyncResult > & result) const
 Collects the result of a previous call to g_subprocess_wait_check_async(). More...
 
int get_status () const
 Gets the raw status code of the process, as from waitpid(). More...
 
bool get_successful () const
 Checks if the process was "successful". More...
 
bool get_if_exited () const
 Check if the given subprocess exited normally (ie: by way of exit() or return from main()). More...
 
int get_exit_status () const
 Check the exit status of the subprocess, given that it exited normally. More...
 
bool get_if_signaled () const
 Check if the given subprocess terminated in response to a signal. More...
 
int get_term_sig () const
 Get the signal number that caused the subprocess to terminate, given that it terminated due to a signal. More...
 
std::pair< Glib::RefPtr< Glib::Bytes >, Glib::RefPtr< Glib::Bytes > > communicate (const Glib::RefPtr< const Glib::Bytes > & stdin_buf, const Glib::RefPtr< Cancellable > & cancellable={})
 Communicate with the subprocess until it terminates, and all input and output has been completed. More...
 
void communicate_async (const Glib::RefPtr< const Glib::Bytes > & stdin_buf, const SlotAsyncReady & slot, const Glib::RefPtr< Cancellable > & cancellable={})
 Asynchronous version of g_subprocess_communicate(). More...
 
std::pair< Glib::RefPtr< Glib::Bytes >, Glib::RefPtr< Glib::Bytes > > communicate_finish (const Glib::RefPtr< AsyncResult > & result)
 Complete an invocation of communicate_async(). More...
 
std::pair< Glib::ustring, Glib::ustringcommunicate_utf8 (const Glib::ustring & stdin_buf, const Glib::RefPtr< Cancellable > & cancellable={})
 Like communicate(), but validates the output of the process as UTF-8, and returns it as a regular Glib::ustring. More...
 
void communicate_utf8_async (const Glib::ustring & stdin_buf, const SlotAsyncReady & slot, const Glib::RefPtr< Cancellable > & cancellable={})
 Asynchronous version of g_subprocess_communicate_utf8(). More...
 
std::pair< Glib::ustring, Glib::ustringcommunicate_utf8_finish (const Glib::RefPtr< AsyncResult > & result)
 Complete an invocation of communicate_utf8_async(). More...
 
- Public Member Functions inherited from Glib::Object
 Object (const Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object && src) noexcept
 
Objectoperator= (Object && src) noexcept
 
void * get_data (const QueryQuark & key)
 
void set_data (const Quark & key, void *data)
 
void set_data_with_c_callback (const Quark & key, void *data, GDestroyNotify notify)
 
void set_data (const Quark & key, void *data, DestroyNotify notify)
 Prefer set_data_with_c_callback() with a callback with C linkage. More...
 
void remove_data (const QueryQuark & quark)
 
void * steal_data (const QueryQuark & quark)
 
- Public Member Functions inherited from Glib::ObjectBase
 ObjectBase (const ObjectBase &)=delete
 
ObjectBaseoperator= (const ObjectBase &)=delete
 
void set_property_value (const Glib::ustring & property_name, const Glib::ValueBase & value)
 You probably want to use a specific property_*() accessor method instead. More...
 
void get_property_value (const Glib::ustring & property_name, Glib::ValueBase & value) const
 You probably want to use a specific property_*() accessor method instead. More...
 
template<class PropertyType >
void set_property (const Glib::ustring & property_name, const PropertyType & value)
 You probably want to use a specific property_*() accessor method instead. More...
 
template<class PropertyType >
void get_property (const Glib::ustring & property_name, PropertyType & value) const
 You probably want to use a specific property_*() accessor method instead. More...
 
template<class PropertyType >
PropertyType get_property (const Glib::ustring & property_name) const
 You probably want to use a specific property_*() accessor method instead. More...
 
sigc::connection connect_property_changed (const Glib::ustring & property_name, const sigc::slot< void()> & slot)
 You can use the signal_changed() signal of the property proxy instead. More...
 
sigc::connection connect_property_changed (const Glib::ustring & property_name, sigc::slot< void()> && slot)
 You can use the signal_changed() signal of the property proxy instead. More...
 
void freeze_notify ()
 Increases the freeze count on object. More...
 
void thaw_notify ()
 Reverts the effect of a previous call to freeze_notify(). More...
 
virtual void reference () const
 Increment the reference count for this object. More...
 
virtual void unreference () const
 Decrement the reference count for this object. More...
 
GObject * gobj ()
 Provides access to the underlying C GObject. More...
 
const GObject * gobj () const
 Provides access to the underlying C GObject. More...
 
GObject * gobj_copy () const
 Give a ref-ed copy to someone. Use for direct struct access. More...
 
- Public Member Functions inherited from Gio::Initable
 Initable (Initable && src) noexcept
 
Initableoperator= (Initable && src) noexcept
 
 ~Initable () noexcept override
 
GInitable * gobj ()
 Provides access to the underlying C GObject. More...
 
const GInitable * gobj () const
 Provides access to the underlying C GObject. More...
 
- Public Member Functions inherited from Glib::Interface
 Interface ()
 A Default constructor. More...
 
 Interface (Interface && src) noexcept
 
Interfaceoperator= (Interface && src) noexcept
 
 Interface (const Glib::Interface_Class & interface_class)
 Called by constructors of derived classes. More...
 
 Interface (GObject * castitem)
 Called by constructors of derived classes. More...
 
 ~Interface () noexcept override
 
 Interface (const Interface &)=delete
 
Interfaceoperator= (const Interface &)=delete
 
GObject * gobj ()
 
const GObject * gobj () const
 

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 
static Glib::RefPtr< Subprocesscreate (const std::vector< std::string > & argv, Flags flags=Flags::NONE)
 Create a new process with the given flags and argument list. More...
 
- Static Public Member Functions inherited from Gio::Initable
static void add_interface (GType gtype_implementer)
 
static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 

Protected Member Functions

 Subprocess (const std::vector< std::string > & argv, Flags flags=Flags::NONE)
 
- Protected Member Functions inherited from Glib::Object
 Object ()
 
 Object (const Glib::ConstructParams & construct_params)
 
 Object (GObject * castitem)
 
 ~Object () noexcept override
 
- Protected Member Functions inherited from Glib::ObjectBase
 ObjectBase ()
 This default constructor is called implicitly from the constructor of user-derived classes, even if, for instance, Gtk::Button calls a different ObjectBase constructor. More...
 
 ObjectBase (const char * custom_type_name)
 A derived constructor always overrides this choice. More...
 
 ObjectBase (const std::type_info & custom_type_info)
 This constructor is a special feature to allow creation of derived types on the fly, without having to use g_object_new() manually. More...
 
 ObjectBase (ObjectBase && src) noexcept
 
ObjectBaseoperator= (ObjectBase && src) noexcept
 
virtual ~ObjectBase () noexcept=0
 
void initialize (GObject * castitem)
 
void initialize_move (GObject * castitem, Glib::ObjectBase * previous_wrapper)
 
- Protected Member Functions inherited from Gio::Initable
 Initable ()
 You should derive from this class to use it. More...
 
void init (const Glib::RefPtr< Cancellable > & cancellable)
 Initializes the object implementing the interface. More...
 
void init ()
 A init() convenience overload. More...
 
virtual bool init_vfunc (const Glib::RefPtr< Cancellable > & cancellable, GError ** error)
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Gio::Subprocesswrap (GSubprocess * object, bool take_copy=false)
 A Glib::wrap() method for this object. More...
 

Detailed Description

Child processes.

Gio::Subprocess allows the creation of and interaction with child processes.

Processes can be communicated with using standard GIO-style APIs (Gio::InputStream, Gio::OutputStream). There are GIO-style APIs to wait for process termination (cancellable and with an asynchronous variant).

There is an API to force a process to terminate, as well as a race-free API for sending UNIX signals to a subprocess.

One major advantage that GIO brings over the core GLib library is comprehensive API for asynchronous I/O, such as Gio::OutputStream::splice_async(). This makes Gio::Subprocess significantly more powerful and flexible than equivalent APIs in some other languages such as the subprocess.py included with Python. For example, using Gio::Subprocess one could create two child processes, reading standard output from the first, processing it, and writing to the input stream of the second, all without blocking the main loop.

A powerful communicate() API is provided similar to the communicate() method of subprocess.py. This enables very easy interaction with a subprocess that has been opened with pipes.

Gio::Subprocess defaults to tight control over the file descriptors open in the child process, avoiding dangling-fd issues that are caused by a simple fork()/exec(). The only open file descriptors in the spawned process are ones that were explicitly specified by the Gio::Subprocess API (unless Gio::Subprocess::Flags::INHERIT_FDS was specified).

Gio::Subprocess will quickly reap all child processes as they exit, avoiding "zombie processes" remaining around for long periods of time. wait() can be used to wait for this to happen, but it will happen even without the call being explicitly made.

As a matter of principle, Gio::Subprocess has no API that accepts shell-style space-separated strings. It will, however, match the typical shell behaviour of searching the PATH for executables that do not contain a directory separator in their name. By default, the PATH of the current process is used. You can specify Gio::Subprocess::Flags::SEARCH_PATH_FROM_ENVP to use the PATH of the launcher environment instead.

Gio::Subprocess attempts to have a very simple API for most uses (ie: spawning a subprocess with arguments and support for most typical kinds of input and output redirection). See create(). The Gio::SubprocessLauncher API is provided for more complicated cases (advanced types of redirection, environment variable manipulation, change of working directory, child setup functions, etc).

A typical use of Gio::Subprocess will involve calling create(), followed by wait_async() or wait(). After the process exits, the status can be checked using functions such as get_if_exited() (which are similar to the familiar WIFEXITED-style POSIX macros).

See also
Gio::SubprocessLauncher
Since glibmm 2.78:

Constructor & Destructor Documentation

◆ Subprocess() [1/2]

Gio::Subprocess::Subprocess ( Subprocess &&  src)
noexcept

◆ ~Subprocess()

Gio::Subprocess::~Subprocess ( )
overridenoexcept

◆ Subprocess() [2/2]

Gio::Subprocess::Subprocess ( const std::vector< std::string > &  argv,
Flags  flags = Flags::NONE 
)
explicitprotected

Member Function Documentation

◆ communicate()

std::pair< Glib::RefPtr< Glib::Bytes >, Glib::RefPtr< Glib::Bytes > > Gio::Subprocess::communicate ( const Glib::RefPtr< const Glib::Bytes > &  stdin_buf,
const Glib::RefPtr< Cancellable > &  cancellable = {} 
)

Communicate with the subprocess until it terminates, and all input and output has been completed.

If stdin_buf is given, the subprocess must have been created with Gio::Subprocess::Flags::STDIN_PIPE. The given data is fed to the stdin of the subprocess and the pipe is closed (ie: EOF).

At the same time (as not to cause blocking when dealing with large amounts of data), if Gio::Subprocess::Flags::STDOUT_PIPE or Gio::Subprocess::Flags::STDERR_PIPE were used, reads from those streams. The data that was read is returned in stdout_buf and/or the stderr_buf.

If the subprocess was created with Gio::Subprocess::Flags::STDOUT_PIPE, stdout_buf will contain the data read from stdout. Otherwise, for subprocesses not created with Gio::Subprocess::Flags::STDOUT_PIPE, stdout_buf will be set to an empty RefPtr. Similar provisions apply to stderr_buf and Gio::Subprocess::Flags::STDERR_PIPE.

If you desire the stdout and stderr data to be interleaved, create the subprocess with Gio::Subprocess::Flags::STDOUT_PIPE and Gio::Subprocess::Flags::STDERR_MERGE. The merged result will be returned in stdout_buf, and stderr_buf will be set to an empty RefPtr.

In case of any error (including cancellation), an exception will be thrown.

After a normal return (no exception thrown), the subprocess has exited and the exit status inspection APIs (eg: get_if_exited(), get_exit_status()) may be used.

You should not attempt to use any of the subprocess pipes after starting this function, since they may be left in strange states, even if the operation was cancelled. You should especially not attempt to interact with the pipes while the operation is in progress (either from another thread or if using the asynchronous version).

Since glibmm 2.78:
Parameters
stdin_bufData to send to the stdin of the subprocess, or an empty RefPtr.
cancellableA Cancellable.
Returns
{stdout_buf, stderr_buf} stdout data and stderr data. Can be empty RefPtrs, if there are no data.
Exceptions
Glib::Error

◆ communicate_async()

void Gio::Subprocess::communicate_async ( const Glib::RefPtr< const Glib::Bytes > &  stdin_buf,
const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable > &  cancellable = {} 
)

Asynchronous version of g_subprocess_communicate().

Complete invocation with g_subprocess_communicate_finish().

Since glibmm 2.78:
Parameters
stdin_bufInput data, or nullptr.
cancellableCancellable.
slotCallback.

◆ communicate_finish()

std::pair< Glib::RefPtr< Glib::Bytes >, Glib::RefPtr< Glib::Bytes > > Gio::Subprocess::communicate_finish ( const Glib::RefPtr< AsyncResult > &  result)

Complete an invocation of communicate_async().

Since glibmm 2.78:
Parameters
resultResult.
Returns
{stdout_buf, stderr_buf} stdout data and stderr data. Can be empty RefPtrs, if there are no data.
Exceptions
Glib::Error

◆ communicate_utf8()

std::pair< Glib::ustring, Glib::ustring > Gio::Subprocess::communicate_utf8 ( const Glib::ustring stdin_buf,
const Glib::RefPtr< Cancellable > &  cancellable = {} 
)

Like communicate(), but validates the output of the process as UTF-8, and returns it as a regular Glib::ustring.

On error, an exception is thrown.

Since glibmm 2.78:
Parameters
stdin_bufData to send to the stdin of the subprocess, or an empty string.
cancellableA Cancellable.
Returns
{stdout_buf, stderr_buf} stdout data and stderr data.
Exceptions
Glib::Error

◆ communicate_utf8_async()

void Gio::Subprocess::communicate_utf8_async ( const Glib::ustring stdin_buf,
const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable > &  cancellable = {} 
)

Asynchronous version of g_subprocess_communicate_utf8().

Complete invocation with g_subprocess_communicate_utf8_finish().

Since glibmm 2.78:
Parameters
stdin_bufInput data, or nullptr.
cancellableCancellable.
slotCallback.

◆ communicate_utf8_finish()

std::pair< Glib::ustring, Glib::ustring > Gio::Subprocess::communicate_utf8_finish ( const Glib::RefPtr< AsyncResult > &  result)

Complete an invocation of communicate_utf8_async().

Since glibmm 2.78:
Parameters
resultResult.
Returns
{stdout_buf, stderr_buf} stdout data and stderr data.
Exceptions
Glib::Error

◆ create()

static Glib::RefPtr< Subprocess > Gio::Subprocess::create ( const std::vector< std::string > &  argv,
Flags  flags = Flags::NONE 
)
static

Create a new process with the given flags and argument list.

Since glibmm 2.78:
Parameters
argvCommandline arguments for the subprocess.
flagsFlags that define the behaviour of the subprocess.
Returns
A newly created Subprocess. On error, an exception is thrown.
Exceptions
Glib::Error

◆ force_exit()

void Gio::Subprocess::force_exit ( )

Use an operating-system specific method to attempt an immediate, forceful termination of the process.

There is no mechanism to determine whether or not the request itself was successful; however, you can use g_subprocess_wait() to monitor the status of the process after calling this function.

On Unix, this function sends S::IGKILL.

Since glibmm 2.78:

◆ get_exit_status()

int Gio::Subprocess::get_exit_status ( ) const

Check the exit status of the subprocess, given that it exited normally.

This is the value passed to the exit() system call or the return value from main.

This is equivalent to the system WEXITSTATUS macro.

It is an error to call this function before g_subprocess_wait() and unless g_subprocess_get_if_exited() returned true.

Since glibmm 2.78:
Returns
The exit status.

◆ get_identifier()

Glib::ustring Gio::Subprocess::get_identifier ( ) const

On UNIX, returns the process ID as a decimal string.

On Windows, returns the result of GetProcessId() also as a string. If the subprocess has terminated, this will return nullptr.

Since glibmm 2.78:
Returns
The subprocess identifier, or nullptr if the subprocess has terminated.

◆ get_if_exited()

bool Gio::Subprocess::get_if_exited ( ) const

Check if the given subprocess exited normally (ie: by way of exit() or return from main()).

This is equivalent to the system WIFEXITED macro.

It is an error to call this function before g_subprocess_wait() has returned.

Since glibmm 2.78:
Returns
true if the case of a normal exit.

◆ get_if_signaled()

bool Gio::Subprocess::get_if_signaled ( ) const

Check if the given subprocess terminated in response to a signal.

This is equivalent to the system WIFSIGNALED macro.

It is an error to call this function before g_subprocess_wait() has returned.

Since glibmm 2.78:
Returns
true if the case of termination due to a signal.

◆ get_status()

int Gio::Subprocess::get_status ( ) const

Gets the raw status code of the process, as from waitpid().

This value has no particular meaning, but it can be used with the macros defined by the system headers such as WIFEXITED. It can also be used with Glib::spawn_check_wait_status().

It is more likely that you want to use g_subprocess_get_if_exited() followed by g_subprocess_get_exit_status().

It is an error to call this function before g_subprocess_wait() has returned.

Since glibmm 2.78:
Returns
The (meaningless) waitpid() exit status from the kernel.

◆ get_stderr_pipe() [1/2]

Glib::RefPtr< InputStream > Gio::Subprocess::get_stderr_pipe ( )

Gets the InputStream from which to read the stderr output of subprocess.

The process must have been created with Gio::Subprocess::Flags::STDERR_PIPE, otherwise nullptr will be returned.

Since glibmm 2.78:
Returns
The stderr pipe.

◆ get_stderr_pipe() [2/2]

Glib::RefPtr< const InputStream > Gio::Subprocess::get_stderr_pipe ( ) const

Gets the InputStream from which to read the stderr output of subprocess.

The process must have been created with Gio::Subprocess::Flags::STDERR_PIPE, otherwise nullptr will be returned.

Since glibmm 2.78:
Returns
The stderr pipe.

◆ get_stdin_pipe() [1/2]

Glib::RefPtr< OutputStream > Gio::Subprocess::get_stdin_pipe ( )

Gets the OutputStream that you can write to in order to give data to the stdin of subprocess.

The process must have been created with Gio::Subprocess::Flags::STDIN_PIPE and not Gio::Subprocess::Flags::STDIN_INHERIT, otherwise nullptr will be returned.

Since glibmm 2.78:
Returns
The stdout pipe.

◆ get_stdin_pipe() [2/2]

Glib::RefPtr< const OutputStream > Gio::Subprocess::get_stdin_pipe ( ) const

Gets the OutputStream that you can write to in order to give data to the stdin of subprocess.

The process must have been created with Gio::Subprocess::Flags::STDIN_PIPE and not Gio::Subprocess::Flags::STDIN_INHERIT, otherwise nullptr will be returned.

Since glibmm 2.78:
Returns
The stdout pipe.

◆ get_stdout_pipe() [1/2]

Glib::RefPtr< InputStream > Gio::Subprocess::get_stdout_pipe ( )

Gets the InputStream from which to read the stdout output of subprocess.

The process must have been created with Gio::Subprocess::Flags::STDOUT_PIPE, otherwise nullptr will be returned.

Since glibmm 2.78:
Returns
The stdout pipe.

◆ get_stdout_pipe() [2/2]

Glib::RefPtr< const InputStream > Gio::Subprocess::get_stdout_pipe ( ) const

Gets the InputStream from which to read the stdout output of subprocess.

The process must have been created with Gio::Subprocess::Flags::STDOUT_PIPE, otherwise nullptr will be returned.

Since glibmm 2.78:
Returns
The stdout pipe.

◆ get_successful()

bool Gio::Subprocess::get_successful ( ) const

Checks if the process was "successful".

A process is considered successful if it exited cleanly with an exit status of 0, either by way of the exit() system call or return from main().

It is an error to call this function before g_subprocess_wait() has returned.

Since glibmm 2.78:
Returns
true if the process exited cleanly with a exit status of 0.

◆ get_term_sig()

int Gio::Subprocess::get_term_sig ( ) const

Get the signal number that caused the subprocess to terminate, given that it terminated due to a signal.

This is equivalent to the system WTERMSIG macro.

It is an error to call this function before g_subprocess_wait() and unless g_subprocess_get_if_signaled() returned true.

Since glibmm 2.78:
Returns
The signal causing termination.

◆ get_type()

static GType Gio::Subprocess::get_type ( )
static

Get the GType for this class, for use with the underlying GObject type system.

◆ gobj() [1/2]

GSubprocess * Gio::Subprocess::gobj ( )
inline

Provides access to the underlying C GObject.

◆ gobj() [2/2]

const GSubprocess * Gio::Subprocess::gobj ( ) const
inline

Provides access to the underlying C GObject.

◆ gobj_copy()

GSubprocess * Gio::Subprocess::gobj_copy ( )

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

◆ operator=()

Subprocess & Gio::Subprocess::operator= ( Subprocess &&  src)
noexcept

◆ send_signal()

void Gio::Subprocess::send_signal ( int  signal_num)

Sends the UNIX signal signal_num to the subprocess, if it is still running.

This API is race-free. If the subprocess has terminated, it will not be signalled.

This API is not available on Windows.

Since glibmm 2.78:
Parameters
signal_numThe signal number to send.

◆ wait()

void Gio::Subprocess::wait ( const Glib::RefPtr< Cancellable > &  cancellable = {}) const

Synchronously wait for the subprocess to terminate.

After the process terminates you can query its exit status with functions such as g_subprocess_get_if_exited() and g_subprocess_get_exit_status().

This function does not fail in the case of the subprocess having abnormal termination. See g_subprocess_wait_check() for that.

Cancelling cancellable doesn't kill the subprocess. Call g_subprocess_force_exit() if it is desirable.

Since glibmm 2.78:
Parameters
cancellableA Cancellable.
Exceptions
Glib::Error

◆ wait_async()

void Gio::Subprocess::wait_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable > &  cancellable = {} 
) const

Wait for the subprocess to terminate.

This is the asynchronous version of g_subprocess_wait().

Since glibmm 2.78:
Parameters
cancellableA Cancellable, or nullptr.
slotA SlotAsyncReady to call when the operation is complete.

◆ wait_check()

void Gio::Subprocess::wait_check ( const Glib::RefPtr< Cancellable > &  cancellable = {}) const

Combines g_subprocess_wait() with Glib::spawn_check_wait_status().

Since glibmm 2.78:
Parameters
cancellableA Cancellable.
Exceptions
Glib::Error

◆ wait_check_async()

void Gio::Subprocess::wait_check_async ( const SlotAsyncReady &  slot,
const Glib::RefPtr< Cancellable > &  cancellable = {} 
) const

Combines g_subprocess_wait_async() with Glib::spawn_check_wait_status().

This is the asynchronous version of g_subprocess_wait_check().

Since glibmm 2.78:
Parameters
cancellableA Cancellable, or nullptr.
slotA SlotAsyncReady to call when the operation is complete.

◆ wait_check_finish()

void Gio::Subprocess::wait_check_finish ( const Glib::RefPtr< AsyncResult > &  result) const

Collects the result of a previous call to g_subprocess_wait_check_async().

Since glibmm 2.78:
Parameters
resultThe AsyncResult passed to your SlotAsyncReady.
Exceptions
Glib::Error

◆ wait_finish()

void Gio::Subprocess::wait_finish ( const Glib::RefPtr< AsyncResult > &  result) const

Collects the result of a previous call to g_subprocess_wait_async().

Since glibmm 2.78:
Parameters
resultThe AsyncResult passed to your SlotAsyncReady.
Exceptions
Glib::Error

Friends And Related Function Documentation

◆ wrap()

Glib::RefPtr< Gio::Subprocess > wrap ( GSubprocess *  object,
bool  take_copy = false 
)
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.