# Gio::ApplicationCommandLine Class Reference

`#include <giomm/applicationcommandline.h>`

Inheritance diagram for Gio::ApplicationCommandLine:
[legend]

List of all members.

## Public Member Functions

virtual | ~ApplicationCommandLine ()
GApplicationCommandLine* | gobj ()
| Provides access to the underlying C GObject.
const GApplicationCommandLine* | gobj () const
| Provides access to the underlying C GObject.
GApplicationCommandLine* | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
char** | get_arguments (int& argc) const
| Gets the list of arguments that was passed on the command line.
std::string | get_cwd () const
| Gets the working directory of the command line invocation.
std::vector< std::string > | get_environ () const
| Gets the contents of the 'environ' variable of the command line invocation, as would be returned by Glib::get_environ().
std::string | getenv (const Glib::ustring& name) const
| Gets the value of a particular environment variable of the command line invocation, as would be returned by Glib::getenv().
bool | is_remote () const
| Determines if cmdline represents a remote invocation.
void | set_exit_status (int exit_status)
| Sets the exit status that will be used when the invoking process exits.
int | get_exit_status () const
| Gets the exit status of cmdline.
void | print (const Glib::ustring& message)
| Formats a message and prints it using the stdout print handler in the invoking process.
void | printerr (const Glib::ustring& message)
| Formats a message and prints it using the stderr print handler in the invoking process.

## Protected Member Functions

| ApplicationCommandLine ()

## Related Functions

(Note that these are not member functions.)
Glib::RefPtr < Gio::ApplicationCommandLine > | wrap (GApplicationCommandLine* object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Constructor & Destructor Documentation

virtual Gio::ApplicationCommandLine::~ApplicationCommandLine | ( | ) | `[virtual]`

Gio::ApplicationCommandLine::ApplicationCommandLine | ( | ) | `[protected]`

## Member Function Documentation

char** Gio::ApplicationCommandLine::get_arguments | ( | int & | argc ) | const

Gets the list of arguments that was passed on the command line.

The strings in the array may contain non-utf8 data.

The return value is `0`-terminated and should be freed using Glib::strfreev().

Since glibmm 2.28:

Parameters:

  argc | The length of the arguments array, or `0`.

Returns:
  The string array containing the arguments (the argv).

std::string Gio::ApplicationCommandLine::get_cwd | ( | ) | const

Gets the working directory of the command line invocation.

The string may contain non-utf8 data.

It is possible that the remote application did not send a working directory, so this may be `0`.

The return value should not be modified or freed and is valid for as long as cmdline exists.

Since glibmm 2.28:

Returns:
  The current directory, or `0`.

std::vector<std::string> Gio::ApplicationCommandLine::get_environ | ( | ) | const

Gets the contents of the 'environ' variable of the command line invocation, as would be returned by Glib::get_environ().

The strings may contain non-utf8 data.

The remote application usually does not send an environment. Use APPLICATION_SEND_ENVIRONMENT to affect that. Even with this flag set it is possible that the environment is still not available (due to invocation messages from other applications).

The return value should not be modified or freed and is valid for as long as cmdline exists.

Since glibmm 2.28:

Returns:
  The environment strings, or `0` if they were not sent.

int Gio::ApplicationCommandLine::get_exit_status | ( | ) | const

Gets the exit status of cmdline.

See g_application_command_line_set_exit_status() for more information.

Since glibmm 2.28:

Returns:
  The exit status.

std::string Gio::ApplicationCommandLine::getenv | ( | const Glib::ustring& | name ) | const

Gets the value of a particular environment variable of the command line invocation, as would be returned by Glib::getenv().

The strings may contain non-utf8 data.

The remote application usually does not send an environment. Use APPLICATION_SEND_ENVIRONMENT to affect that. Even with this flag set it is possible that the environment is still not available (due to invocation messages from other applications).

The return value should not be modified or freed and is valid for as long as cmdline exists.

Since glibmm 2.28:

Parameters:

  name | The environment variable to get.

Returns:
  The value of the variable, or `0` if unset or unsent.

const GApplicationCommandLine* Gio::ApplicationCommandLine::gobj | ( | ) | const`[inline]`

Provides access to the underlying C GObject.

Reimplemented from Glib::ObjectBase.

GApplicationCommandLine* Gio::ApplicationCommandLine::gobj | ( | ) | `[inline]`

Provides access to the underlying C GObject.

Reimplemented from Glib::ObjectBase.

GApplicationCommandLine* Gio::ApplicationCommandLine::gobj_copy | ( | ) |

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

bool Gio::ApplicationCommandLine::is_remote | ( | ) | const

Determines if cmdline represents a remote invocation.

Since glibmm 2.28:

Returns:
  `true` if the invocation was remote.

void Gio::ApplicationCommandLine::print | ( | const Glib::ustring& | message ) |

Formats a message and prints it using the stdout print handler in the invoking process.

If this is a local invocation then this is exactly equivalent to g_print(). If this is remote then this is equivalent to calling g_print() in the invoking process.

Parameters:

  message | The text to print.

void Gio::ApplicationCommandLine::printerr | ( | const Glib::ustring& | message ) |

Formats a message and prints it using the stderr print handler in the invoking process.

If this is a local invocation then this is exactly equivalent to g_printerr(). If this is remote then this is equivalent to calling g_printerr() in the invoking process.

Parameters:

  message | The text to print.

void Gio::ApplicationCommandLine::set_exit_status | ( | int | exit_status ) |

Sets the exit status that will be used when the invoking process exits.

The return value of the Application::command-line signal is passed to this function when the handler returns. This is the usual way of setting the exit status.

In the event that you want the remote invocation to continue running and want to decide on the exit status in the future, you can use this call. For the case of a remote invocation, the remote process will typically exit when the last reference is dropped on cmdline. The exit status of the remote process will be equal to the last value that was set with this function.

In the case that the commandline invocation is local, the situation is slightly more complicated. If the commandline invocation results in the mainloop running (ie: because the use-count of the application increased to a non-zero value) then the application is considered to have been 'successful' in a certain sense, and the exit status is always zero. If the application use count is zero, though, the exit status of the local ApplicationCommandLine is used.

Since glibmm 2.28:

Parameters:

  exit_status | The exit status.

## Friends And Related Function Documentation

Glib::RefPtr< Gio::ApplicationCommandLine > wrap | ( | GApplicationCommandLine * | object,
|  | bool | take_copy = `false`
| ) |  | `[related]`

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

Parameters:

  object | The C instance.
  take_copy | False 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.