Xfce Foundation Classes
Main Page  | IndexNamespace List  |  Alphabetical List  |  Class List  |  File List


Xfc::G::SpawnSync Class Reference

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

#include <xfc/glib/spawn.hh>

Inheritance diagram for Xfc::G::SpawnSync:

Xfc::G::Spawn Xfc::StackObject List of all members.

Public Member Functions

Accessors
Methods

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

Xfc::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.

Xfc::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.

Xfc::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.

Xfc::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

int Xfc::G::SpawnSync::exit_status (  )  const

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

Returns:
The exit status.

std::string Xfc::G::SpawnSync::standard_output (  )  const

Returns the child output as a std::string.

Returns:
A std::string.
If an error occurs the return string will be empty.

bool Xfc::G::SpawnSync::execute ( G::Error error = 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, or null to ignore errors.
Returns:
true if successful, false if error is set.

bool Xfc::G::SpawnSync::execute ( const ChildSetupSlot slot,
G::Error error = 0 
)

Executes a child program synchronously (that is, waits for the child to exit before returning).

Parameters:
slot A sigc::slot to call in the child just before exec().
error The return location for a G::Error, or null to ignore errors.
Returns:
true if successful, false if error is set.


The documentation for this class was generated from the following file: Xfce Foundation Classes
Copyright © 2004-2005 The XFC Development Team XFC 4.3