1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>GApplicationCommandLine</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
7 <link rel="home" href="index.html" title="GIO Reference Manual">
8 <link rel="up" href="application.html" title="Application support">
9 <link rel="prev" href="GApplication.html" title="GApplication">
10 <link rel="next" href="GActionGroup.html" title="GActionGroup">
11 <meta name="generator" content="GTK-Doc V1.18 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
14 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
17 <td><a accesskey="p" href="GApplication.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
18 <td><a accesskey="u" href="application.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
19 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
20 <th width="100%" align="center">GIO Reference Manual</th>
21 <td><a accesskey="n" href="GActionGroup.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
23 <tr><td colspan="5" class="shortcuts">
24 <a href="#GApplicationCommandLine.synopsis" class="shortcut">Top</a>
26 <a href="#GApplicationCommandLine.description" class="shortcut">Description</a>
28 <a href="#GApplicationCommandLine.object-hierarchy" class="shortcut">Object Hierarchy</a>
31 <div class="refentry">
32 <a name="GApplicationCommandLine"></a><div class="titlepage"></div>
33 <div class="refnamediv"><table width="100%"><tr>
35 <h2><span class="refentrytitle"><a name="GApplicationCommandLine.top_of_page"></a>GApplicationCommandLine</span></h2>
36 <p>GApplicationCommandLine — A command-line invocation of an application</p>
38 <td valign="top" align="right"></td>
40 <div class="refsynopsisdiv">
41 <a name="GApplicationCommandLine.synopsis"></a><h2>Synopsis</h2>
42 <pre class="synopsis"> <a class="link" href="GApplicationCommandLine.html#GApplicationCommandLine-struct" title="GApplicationCommandLine">GApplicationCommandLine</a>;
43 struct <a class="link" href="GApplicationCommandLine.html#GApplicationCommandLineClass" title="struct GApplicationCommandLineClass">GApplicationCommandLineClass</a>;
45 <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> ** <a class="link" href="GApplicationCommandLine.html#g-application-command-line-get-arguments" title="g_application_command_line_get_arguments ()">g_application_command_line_get_arguments</a>
46 (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
47 <em class="parameter"><code><span class="type">int</span> *argc</code></em>);
48 const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="GApplicationCommandLine.html#g-application-command-line-get-cwd" title="g_application_command_line_get_cwd ()">g_application_command_line_get_cwd</a> (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);
49 const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> * const * <a class="link" href="GApplicationCommandLine.html#g-application-command-line-get-environ" title="g_application_command_line_get_environ ()">g_application_command_line_get_environ</a>
50 (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);
51 const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="GApplicationCommandLine.html#g-application-command-line-getenv" title="g_application_command_line_getenv ()">g_application_command_line_getenv</a> (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
52 <em class="parameter"><code>const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *name</code></em>);
53 <a href="./../glib/glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a> <a class="link" href="GApplicationCommandLine.html#g-application-command-line-get-is-remote" title="g_application_command_line_get_is_remote ()">g_application_command_line_get_is_remote</a>
54 (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);
55 <a href="./../glib/glib/glib-GVariant.html#GVariant"><span class="returnvalue">GVariant</span></a> * <a class="link" href="GApplicationCommandLine.html#g-application-command-line-get-platform-data" title="g_application_command_line_get_platform_data ()">g_application_command_line_get_platform_data</a>
56 (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);
58 <span class="returnvalue">void</span> <a class="link" href="GApplicationCommandLine.html#g-application-command-line-set-exit-status" title="g_application_command_line_set_exit_status ()">g_application_command_line_set_exit_status</a>
59 (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
60 <em class="parameter"><code><span class="type">int</span> exit_status</code></em>);
61 <span class="returnvalue">int</span> <a class="link" href="GApplicationCommandLine.html#g-application-command-line-get-exit-status" title="g_application_command_line_get_exit_status ()">g_application_command_line_get_exit_status</a>
62 (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);
64 <span class="returnvalue">void</span> <a class="link" href="GApplicationCommandLine.html#g-application-command-line-print" title="g_application_command_line_print ()">g_application_command_line_print</a> (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
65 <em class="parameter"><code>const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *format</code></em>,
66 <em class="parameter"><code>...</code></em>);
67 <span class="returnvalue">void</span> <a class="link" href="GApplicationCommandLine.html#g-application-command-line-printerr" title="g_application_command_line_printerr ()">g_application_command_line_printerr</a> (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
68 <em class="parameter"><code>const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *format</code></em>,
69 <em class="parameter"><code>...</code></em>);
72 <div class="refsect1">
73 <a name="GApplicationCommandLine.object-hierarchy"></a><h2>Object Hierarchy</h2>
74 <pre class="synopsis">
75 <a href="./../gobject/gobject/gobject-The-Base-Object-Type.html#GObject">GObject</a>
76 +----GApplicationCommandLine
79 <div class="refsect1">
80 <a name="GApplicationCommandLine.description"></a><h2>Description</h2>
82 <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> represents a command-line invocation of
83 an application. It is created by <a class="link" href="GApplication.html" title="GApplication"><span class="type">GApplication</span></a> and emitted
84 in the <a class="link" href="GApplication.html#GApplication-command-line" title='The "command-line" signal'><span class="type">"command-line"</span></a> signal and virtual function.
87 The class contains the list of arguments that the program was invoked
88 with. It is also possible to query if the commandline invocation was
89 local (ie: the current process is running in direct response to the
90 invocation) or remote (ie: some other process forwarded the
91 commandline to this process).
94 The GApplicationCommandLine object can provide the <em class="parameter"><code>argc</code></em> and <em class="parameter"><code>argv</code></em>
95 parameters for use with the <a href="./../glib/glib/glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a> command-line parsing API,
96 with the <a class="link" href="GApplicationCommandLine.html#g-application-command-line-get-arguments" title="g_application_command_line_get_arguments ()"><code class="function">g_application_command_line_get_arguments()</code></a> function. See
97 <a class="xref" href="GApplicationCommandLine.html#gapplication-example-cmdline3" title="Example 19. Deferred commandline handling">Example 19, “Deferred commandline handling”</a> for an example.
100 The exit status of the originally-invoked process may be set and
101 messages can be printed to stdout or stderr of that process. The
102 lifecycle of the originally-invoked process is tied to the lifecycle
103 of this object (ie: the process exits when the last reference is
107 The main use for <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> (and the
108 <a class="link" href="GApplication.html#GApplication-command-line" title='The "command-line" signal'><span class="type">"command-line"</span></a> signal) is 'Emacs server' like use cases:
109 You can set the <code class="envar">EDITOR</code> environment variable to have
110 e.g. git use your favourite editor to edit commit messages, and if you
111 already have an instance of the editor running, the editing will happen
112 in the running instance, instead of opening a new one. An important
113 aspect of this use case is that the process that gets started by git
114 does not return until the editing is done.
118 <div class="example">
119 <a name="gapplication-example-cmdline"></a><p class="title"><b>Example 17. Handling commandline arguments with GApplication</b></p>
120 <div class="example-contents">
122 A simple example where the commandline is completely handled
123 in the <a class="link" href="GApplication.html#GApplication-command-line" title='The "command-line" signal'><span class="type">"command-line"</span></a> handler. The launching instance exits
124 once the signal handler in the primary instance has returned, and the
125 return value of the signal handler becomes the exit status of the launching
128 <pre class="programlisting">
129 #include <gio/gio.h>
130 #include <stdlib.h>
131 #include <string.h>
134 command_line (GApplication *application,
135 GApplicationCommandLine *cmdline)
141 argv = g_application_command_line_get_arguments (cmdline, &argc);
143 g_application_command_line_print (cmdline,
144 "This text is written back\n"
145 "to stdout of the caller\n");
147 for (i = 0; i < argc; i++)
148 g_print ("argument %d: %s\n", i, argv[i]);
156 main (int argc, char **argv)
161 app = g_application_new ("org.gtk.TestApplication",
162 G_APPLICATION_HANDLES_COMMAND_LINE);
163 g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
164 g_application_set_inactivity_timeout (app, 10000);
166 status = g_application_run (app, argc, argv);
168 g_object_unref (app);
176 <p><br class="example-break">
180 <div class="example">
181 <a name="gapplication-example-cmdline2"></a><p class="title"><b>Example 18. Split commandline handling</b></p>
182 <div class="example-contents">
184 An example of split commandline handling. Options that start with
185 <code class="literal">--local-</code> are handled locally, all other options are
186 passed to the <a class="link" href="GApplication.html#GApplication-command-line" title='The "command-line" signal'><span class="type">"command-line"</span></a> handler which runs in the primary
189 <pre class="programlisting">
190 #include <gio/gio.h>
191 #include <stdlib.h>
192 #include <string.h>
195 command_line (GApplication *application,
196 GApplicationCommandLine *cmdline)
202 argv = g_application_command_line_get_arguments (cmdline, &argc);
204 for (i = 0; i < argc; i++)
205 g_print ("handling argument %s remotely\n", argv[i]);
213 test_local_cmdline (GApplication *application,
225 if (g_str_has_prefix (argv[i], "--local-"))
227 g_print ("handling argument %s locally\n", argv[i]);
229 for (j = i; argv[j]; j++)
230 argv[j] = argv[j + 1];
234 g_print ("not handling argument %s locally\n", argv[i]);
244 typedef GApplication TestApplication;
245 typedef GApplicationClass TestApplicationClass;
247 static GType test_application_get_type (void);
248 G_DEFINE_TYPE (TestApplication, test_application, G_TYPE_APPLICATION)
251 test_application_finalize (GObject *object)
253 G_OBJECT_CLASS (test_application_parent_class)->finalize (object);
257 test_application_init (TestApplication *app)
262 test_application_class_init (TestApplicationClass *class)
264 G_OBJECT_CLASS (class)->finalize = test_application_finalize;
265 G_APPLICATION_CLASS (class)->local_command_line = test_local_cmdline;
268 static GApplication *
269 test_application_new (const gchar *application_id,
270 GApplicationFlags flags)
272 g_return_val_if_fail (g_application_id_is_valid (application_id), NULL);
276 return g_object_new (test_application_get_type (),
277 "application-id", application_id,
283 main (int argc, char **argv)
288 app = test_application_new ("org.gtk.TestApplication", 0);
289 g_application_set_inactivity_timeout (app, 10000);
290 g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
292 status = g_application_run (app, argc, argv);
294 g_object_unref (app);
302 <p><br class="example-break">
306 <div class="example">
307 <a name="gapplication-example-cmdline3"></a><p class="title"><b>Example 19. Deferred commandline handling</b></p>
308 <div class="example-contents">
310 An example of deferred commandline handling. Here, the commandline is
311 not completely handled before the <a class="link" href="GApplication.html#GApplication-command-line" title='The "command-line" signal'><span class="type">"command-line"</span></a> handler
312 returns. Instead, we keep a reference to the GApplicationCommandLine
313 object and handle it later(in this example, in an idle). Note that it
314 is necessary to hold the application until you are done with the
318 This example also shows how to use <a href="./../glib/glib/glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a> for parsing the
319 commandline arguments. Note that it is necessary to disable the
320 built-in help-handling of <a href="./../glib/glib/glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a>, since it calls <code class="function">exit()</code>
321 after printing help, which is not what you want to happen in
322 the primary instance.
324 <pre class="programlisting">
325 #include <gio/gio.h>
326 #include <stdlib.h>
327 #include <string.h>
330 my_cmdline_handler (gpointer data)
332 GApplicationCommandLine *cmdline = data;
339 GOptionContext *context;
340 GOptionEntry entries[] = {
341 { "arg1", 0, 0, G_OPTION_ARG_INT, &arg1, NULL, NULL },
342 { "arg2", 0, 0, G_OPTION_ARG_NONE, &arg2, NULL, NULL },
343 { "help", '?', 0, G_OPTION_ARG_NONE, &help, NULL, NULL },
349 args = g_application_command_line_get_arguments (cmdline, &argc);
351 /* We have to make an extra copy of the array, since g_option_context_parse()
352 * assumes that it can remove strings from the array without freeing them.
354 argv = g_new (gchar*, argc + 1);
355 for (i = 0; i <= argc; i++)
358 context = g_option_context_new (NULL);
359 g_option_context_set_help_enabled (context, FALSE);
360 g_option_context_add_main_entries (context, entries, NULL);
366 if (!g_option_context_parse (context, &argc, &argv, &error))
368 g_application_command_line_printerr (cmdline, "%s\n", error->message);
369 g_error_free (error);
370 g_application_command_line_set_exit_status (cmdline, 1);
375 text = g_option_context_get_help (context, FALSE, NULL);
376 g_application_command_line_print (cmdline, "%s", text);
381 g_application_command_line_print (cmdline, "arg1 is %d and arg2 is %s\n",
382 arg1, arg2 ? "TRUE" : "FALSE");
383 g_application_command_line_set_exit_status (cmdline, 0);
389 g_option_context_free (context);
391 /* we are done handling this commandline */
392 g_object_unref (cmdline);
394 return G_SOURCE_REMOVE;
398 command_line (GApplication *application,
399 GApplicationCommandLine *cmdline)
401 /* keep the application running until we are done with this commandline */
402 g_application_hold (application);
404 g_object_set_data_full (G_OBJECT (cmdline),
405 "application", application,
406 (GDestroyNotify)g_application_release);
408 g_object_ref (cmdline);
409 g_idle_add (my_cmdline_handler, cmdline);
415 main (int argc, char **argv)
420 app = g_application_new ("org.gtk.TestApplication",
421 G_APPLICATION_HANDLES_COMMAND_LINE);
422 g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
423 g_application_set_inactivity_timeout (app, 10000);
425 status = g_application_run (app, argc, argv);
427 g_object_unref (app);
435 <p><br class="example-break">
438 <div class="refsect1">
439 <a name="GApplicationCommandLine.details"></a><h2>Details</h2>
440 <div class="refsect2">
441 <a name="GApplicationCommandLine-struct"></a><h3>GApplicationCommandLine</h3>
442 <pre class="programlisting">typedef struct _GApplicationCommandLine GApplicationCommandLine;</pre>
445 <div class="refsect2">
446 <a name="GApplicationCommandLineClass"></a><h3>struct GApplicationCommandLineClass</h3>
447 <pre class="programlisting">struct GApplicationCommandLineClass {
451 The <span class="structname">GApplicationCommandLineClass</span> structure
452 contains private data only
454 <p class="since">Since 2.28</p>
457 <div class="refsect2">
458 <a name="g-application-command-line-get-arguments"></a><h3>g_application_command_line_get_arguments ()</h3>
459 <pre class="programlisting"><a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> ** g_application_command_line_get_arguments
460 (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
461 <em class="parameter"><code><span class="type">int</span> *argc</code></em>);</pre>
463 Gets the list of arguments that was passed on the command line.
466 The strings in the array may contain non-utf8 data.
469 The return value is <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>-terminated and should be freed using
470 <a href="./../glib/glib/glib-String-Utility-Functions.html#g-strfreev"><code class="function">g_strfreev()</code></a>.
472 <div class="variablelist"><table border="0">
473 <col align="left" valign="top">
476 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
477 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
481 <td><p><span class="term"><em class="parameter"><code>argc</code></em> :</span></p></td>
482 <td>the length of the arguments array, or <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="Parameter for returning results. Default is transfer full."><span class="acronym">out</span></acronym>][<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
486 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
488 containing the arguments (the argv). <span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=argc][<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span>
493 <p class="since">Since 2.28</p>
496 <div class="refsect2">
497 <a name="g-application-command-line-get-cwd"></a><h3>g_application_command_line_get_cwd ()</h3>
498 <pre class="programlisting">const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> * g_application_command_line_get_cwd (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);</pre>
500 Gets the working directory of the command line invocation.
501 The string may contain non-utf8 data.
504 It is possible that the remote application did not send a working
505 directory, so this may be <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.
508 The return value should not be modified or freed and is valid for as
509 long as <em class="parameter"><code>cmdline</code></em> exists.
511 <div class="variablelist"><table border="0">
512 <col align="left" valign="top">
515 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
516 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
520 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
521 <td>the current directory, or <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>
526 <p class="since">Since 2.28</p>
529 <div class="refsect2">
530 <a name="g-application-command-line-get-environ"></a><h3>g_application_command_line_get_environ ()</h3>
531 <pre class="programlisting">const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> * const * g_application_command_line_get_environ
532 (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);</pre>
534 Gets the contents of the 'environ' variable of the command line
535 invocation, as would be returned by <a href="./../glib/glib/glib-Miscellaneous-Utility-Functions.html#g-get-environ"><code class="function">g_get_environ()</code></a>, ie as a
536 <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>-terminated list of strings in the form 'NAME=VALUE'.
537 The strings may contain non-utf8 data.
540 The remote application usually does not send an environment. Use
541 <a class="link" href="GApplication.html#G-APPLICATION-SEND-ENVIRONMENT:CAPS"><code class="literal">G_APPLICATION_SEND_ENVIRONMENT</code></a> to affect that. Even with this flag
542 set it is possible that the environment is still not available (due
543 to invocation messages from other applications).
546 The return value should not be modified or freed and is valid for as
547 long as <em class="parameter"><code>cmdline</code></em> exists.
550 See <a class="link" href="GApplicationCommandLine.html#g-application-command-line-getenv" title="g_application_command_line_getenv ()"><code class="function">g_application_command_line_getenv()</code></a> if you are only interested
551 in the value of a single environment variable.
553 <div class="variablelist"><table border="0">
554 <col align="left" valign="top">
557 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
558 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
562 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
564 strings, or <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> if they were not sent. <span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> zero-terminated=1][<acronym title="Don't free data after the code is done."><span class="acronym">transfer none</span></acronym>]</span>
569 <p class="since">Since 2.28</p>
572 <div class="refsect2">
573 <a name="g-application-command-line-getenv"></a><h3>g_application_command_line_getenv ()</h3>
574 <pre class="programlisting">const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> * g_application_command_line_getenv (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
575 <em class="parameter"><code>const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *name</code></em>);</pre>
577 Gets the value of a particular environment variable of the command
578 line invocation, as would be returned by <a href="./../glib/glib/glib-Miscellaneous-Utility-Functions.html#g-getenv"><code class="function">g_getenv()</code></a>. The strings may
579 contain non-utf8 data.
582 The remote application usually does not send an environment. Use
583 <a class="link" href="GApplication.html#G-APPLICATION-SEND-ENVIRONMENT:CAPS"><code class="literal">G_APPLICATION_SEND_ENVIRONMENT</code></a> to affect that. Even with this flag
584 set it is possible that the environment is still not available (due
585 to invocation messages from other applications).
588 The return value should not be modified or freed and is valid for as
589 long as <em class="parameter"><code>cmdline</code></em> exists.
591 <div class="variablelist"><table border="0">
592 <col align="left" valign="top">
595 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
596 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
600 <td><p><span class="term"><em class="parameter"><code>name</code></em> :</span></p></td>
601 <td>the environment variable to get</td>
604 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
605 <td>the value of the variable, or <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> if unset or unsent</td>
609 <p class="since">Since 2.28</p>
612 <div class="refsect2">
613 <a name="g-application-command-line-get-is-remote"></a><h3>g_application_command_line_get_is_remote ()</h3>
614 <pre class="programlisting"><a href="./../glib/glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a> g_application_command_line_get_is_remote
615 (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);</pre>
617 Determines if <em class="parameter"><code>cmdline</code></em> represents a remote invocation.
619 <div class="variablelist"><table border="0">
620 <col align="left" valign="top">
623 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
624 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
628 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
630 <a href="./../glib/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if the invocation was remote</td>
634 <p class="since">Since 2.28</p>
637 <div class="refsect2">
638 <a name="g-application-command-line-get-platform-data"></a><h3>g_application_command_line_get_platform_data ()</h3>
639 <pre class="programlisting"><a href="./../glib/glib/glib-GVariant.html#GVariant"><span class="returnvalue">GVariant</span></a> * g_application_command_line_get_platform_data
640 (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);</pre>
642 Gets the platform data associated with the invocation of <em class="parameter"><code>cmdline</code></em>.
645 This is a <a href="./../glib/glib/glib-GVariant.html#GVariant"><span class="type">GVariant</span></a> dictionary containing information about the
646 context in which the invocation occurred. It typically contains
647 information like the current working directory and the startup
651 For local invocation, it will be <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.
653 <div class="variablelist"><table border="0">
654 <col align="left" valign="top">
657 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
658 <td><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a></td>
661 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
662 <td>the platform data, or <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
667 <p class="since">Since 2.28</p>
670 <div class="refsect2">
671 <a name="g-application-command-line-set-exit-status"></a><h3>g_application_command_line_set_exit_status ()</h3>
672 <pre class="programlisting"><span class="returnvalue">void</span> g_application_command_line_set_exit_status
673 (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
674 <em class="parameter"><code><span class="type">int</span> exit_status</code></em>);</pre>
676 Sets the exit status that will be used when the invoking process
680 The return value of the <a class="link" href="GApplication.html#GApplication-command-line" title='The "command-line" signal'><span class="type">"command-line"</span></a> signal is
681 passed to this function when the handler returns. This is the usual
682 way of setting the exit status.
685 In the event that you want the remote invocation to continue running
686 and want to decide on the exit status in the future, you can use this
687 call. For the case of a remote invocation, the remote process will
688 typically exit when the last reference is dropped on <em class="parameter"><code>cmdline</code></em>. The
689 exit status of the remote process will be equal to the last value
690 that was set with this function.
693 In the case that the commandline invocation is local, the situation
694 is slightly more complicated. If the commandline invocation results
695 in the mainloop running (ie: because the use-count of the application
696 increased to a non-zero value) then the application is considered to
697 have been 'successful' in a certain sense, and the exit status is
698 always zero. If the application use count is zero, though, the exit
699 status of the local <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> is used.
701 <div class="variablelist"><table border="0">
702 <col align="left" valign="top">
705 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
706 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
710 <td><p><span class="term"><em class="parameter"><code>exit_status</code></em> :</span></p></td>
711 <td>the exit status</td>
715 <p class="since">Since 2.28</p>
718 <div class="refsect2">
719 <a name="g-application-command-line-get-exit-status"></a><h3>g_application_command_line_get_exit_status ()</h3>
720 <pre class="programlisting"><span class="returnvalue">int</span> g_application_command_line_get_exit_status
721 (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);</pre>
723 Gets the exit status of <em class="parameter"><code>cmdline</code></em>. See
724 <a class="link" href="GApplicationCommandLine.html#g-application-command-line-set-exit-status" title="g_application_command_line_set_exit_status ()"><code class="function">g_application_command_line_set_exit_status()</code></a> for more information.
726 <div class="variablelist"><table border="0">
727 <col align="left" valign="top">
730 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
731 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
735 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
736 <td>the exit status</td>
740 <p class="since">Since 2.28</p>
743 <div class="refsect2">
744 <a name="g-application-command-line-print"></a><h3>g_application_command_line_print ()</h3>
745 <pre class="programlisting"><span class="returnvalue">void</span> g_application_command_line_print (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
746 <em class="parameter"><code>const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *format</code></em>,
747 <em class="parameter"><code>...</code></em>);</pre>
749 Formats a message and prints it using the stdout print handler in the
753 If <em class="parameter"><code>cmdline</code></em> is a local invocation then this is exactly equivalent to
754 <a href="./../glib/glib/glib-Warnings-and-Assertions.html#g-print"><code class="function">g_print()</code></a>. If <em class="parameter"><code>cmdline</code></em> is remote then this is equivalent to calling
755 <a href="./../glib/glib/glib-Warnings-and-Assertions.html#g-print"><code class="function">g_print()</code></a> in the invoking process.
757 <div class="variablelist"><table border="0">
758 <col align="left" valign="top">
761 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
762 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
766 <td><p><span class="term"><em class="parameter"><code>format</code></em> :</span></p></td>
767 <td>a printf-style format string</td>
770 <td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td>
771 <td>arguments, as per <em class="parameter"><code>format</code></em>
776 <p class="since">Since 2.28</p>
779 <div class="refsect2">
780 <a name="g-application-command-line-printerr"></a><h3>g_application_command_line_printerr ()</h3>
781 <pre class="programlisting"><span class="returnvalue">void</span> g_application_command_line_printerr (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
782 <em class="parameter"><code>const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *format</code></em>,
783 <em class="parameter"><code>...</code></em>);</pre>
785 Formats a message and prints it using the stderr print handler in the
789 If <em class="parameter"><code>cmdline</code></em> is a local invocation then this is exactly equivalent to
790 <a href="./../glib/glib/glib-Warnings-and-Assertions.html#g-printerr"><code class="function">g_printerr()</code></a>. If <em class="parameter"><code>cmdline</code></em> is remote then this is equivalent to
791 calling <a href="./../glib/glib/glib-Warnings-and-Assertions.html#g-printerr"><code class="function">g_printerr()</code></a> in the invoking process.
793 <div class="variablelist"><table border="0">
794 <col align="left" valign="top">
797 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
798 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
802 <td><p><span class="term"><em class="parameter"><code>format</code></em> :</span></p></td>
803 <td>a printf-style format string</td>
806 <td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td>
807 <td>arguments, as per <em class="parameter"><code>format</code></em>
812 <p class="since">Since 2.28</p>
815 <div class="refsect1">
816 <a name="GApplicationCommandLine.see-also"></a><h2>See Also</h2>
817 <a class="link" href="GApplication.html" title="GApplication"><span class="type">GApplication</span></a>
822 Generated by GTK-Doc V1.18</div>