Reference Manual

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# Inti::G::SpawnSync Class Reference

A C++ interface for the GLib synchronous spawn functions. More...

`#include <inti/glib/spawn.h>`

Inheritance diagram for Inti::G::SpawnSync:

List of all members.

## Public Member Functions

Constructors

- SpawnSync (const std::vector< std::string > &argv, SpawnFlagsField flags=0)
    Constructs a synchronous spawn object with the specified arguments argv and spawn flags.
- SpawnSync (const std::string &command_line, G::Error *error)
    Constructs a synchronous spawn object with the specified arguments in the command_line string.
- ~SpawnSync ()
    Destructor.

Accessors

- int exit_status () const
    Returns the exit status of the child, as returned by waitpid().
- std::string standard_output () const
    Returns the child output as a std::string.

Methods

- bool execute (G::Error *error, const ChildSetupSlot *slot=0)
    Executes a child program synchronously (that is, waits for the child to exit before returning).

## Detailed Description

A C++ interface for the GLib synchronous spawn functions.

SpawnSync executes a child synchronously (that is, waits for the child to exit before returning). All output from the child is stored in standard_output and standard_error, if those parameters are set. If exit_status is set, the exit status of the child is stored there as it would be returned by waitpid(); standard UNIX macros such as WIFEXITED() and WEXITSTATUS() must be used to evaluate the exit status. If an error occurs, no data is returned in standard_output, standard_error, or exit_status.

G::SPAWN_STDOUT_TO_DEV_NULL means that the child's standard output will be discarded, instead of going to the same location as the parent's standard output. If you use this flag, set_standard_output() is ignored. G::SPAWN_STDERR_TO_DEV_NULL means that the child's standard error will be discarded, instead of going to the same location as the parent's standard error. If you use this flag, set_standard_error() will be ignored. Do not set the G::SPAWN_DO_NOT_REAP_CHILD flag on a SpawnSync object. If you do execute() will fail and return false.

Example: A simple way to spawn a synchronous child process.

        G::Error error;
        SpawnSync child(command_line, &error);
        if (error.get())
        {
            // handle error.
        }
        else
        {
            if (!child.execute(&error))
            {
                    // handle error
            }
        }

See SpawnAsync for more details.

## Constructor & Destructor Documentation

Inti::G::SpawnSync::SpawnSync | ( | const std::vector< std::string > & | argv,
|  | SpawnFlagsField | flags = 0
| ) |

  | Constructs a synchronous spawn object with the specified arguments argv and spawn flags. Parameters:
  argv | A reference to a vector of std::string that holds the child's argument strings.
  flags | One or more bitflags from the G::SpawnFlags enumeration.
The first string in argv (argv[0]) is of course the name of the program to execute. By default, the name of the program must be a full path; the PATH shell variable will only be searched if you pass the G::SPAWN_SEARCH_PATH flag.

Inti::G::SpawnSync::SpawnSync | ( | const std::string & | command_line,
|  | G::Error * | error
| ) |

  | Constructs a synchronous spawn object with the specified arguments in the command_line string. Parameters:
  command_line | The command line string.
  error | The return location for a G::Error.
This constructor parses command line with g_shell_parse_argv() and passes it to GLib. If an error occurs it is set by the parsing function, and can be any of those from the G_SHELL_ERROR domain. Runs a command_line in the background. Unlike then other constructor, the G::SPAWN_SEARCH_PATH flag is enabled, other flags are not. Note that G::SPAWN_SEARCH_PATH can have security implications, so consider using the other constructor if appropriate.

## Member Function Documentation

bool Inti::G::SpawnSync::execute | ( | G::Error * | error,
|  | const ChildSetupSlot * | slot = 0
| ) |

  | Executes a child program synchronously (that is, waits for the child to exit before returning). Parameters:
  error | The return location for a G::Error.
  slot | A ChildSetupSlot method to run in the child just before exec().
Returns: true if successful, false if error is set.

int Inti::G::SpawnSync::exit_status | ( |  | ) | const

| Returns the exit status of the child, as returned by waitpid(). Returns: The exit status.

std::string Inti::G::SpawnSync::standard_output | ( |  | ) | const

| Returns the child output as a std::string. Returns: A std::string.

The documentation for this class was generated from the following file:

- spawn.h

Main Page - Footer