<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN'
                      'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [
<!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 'http://www.w3.org/2003/XInclude'">
<!ENTITY version SYSTEM "version.xml">
]>
<refentry id="glib-Spawning-Processes">
<refmeta>
<refentrytitle role="top_of_page" id="glib-Spawning-Processes.top_of_page">Spawning Processes</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GLIB Library</refmiscinfo>
</refmeta>
<refnamediv>
<refname>Spawning Processes</refname>
<refpurpose>process launching</refpurpose>
</refnamediv>

<refsect1 id="glib-Spawning-Processes.functions" role="functions_proto">
<title role="functions_proto.title">Functions</title>
<informaltable pgwide="1" frame="none">
<tgroup cols="2">
<colspec colname="functions_return" colwidth="150px"/>
<colspec colname="functions_name"/>
<tbody>
<row><entry role="function_type"><link linkend="void"><returnvalue>void</returnvalue></link>
</entry><entry role="function_name"><phrase role="c_punctuation">(</phrase><link linkend="GSpawnChildSetupFunc">*GSpawnChildSetupFunc</link><phrase role="c_punctuation">)</phrase>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-spawn-async-with-fds">g_spawn_async_with_fds</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-spawn-async-with-pipes">g_spawn_async_with_pipes</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-spawn-async">g_spawn_async</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-spawn-sync">g_spawn_sync</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-spawn-check-exit-status">g_spawn_check_exit_status</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-spawn-command-line-async">g_spawn_command_line_async</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-spawn-command-line-sync">g_spawn_command_line_sync</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>
<row><entry role="function_type"><link linkend="void"><returnvalue>void</returnvalue></link>
</entry><entry role="function_name"><link linkend="g-spawn-close-pid">g_spawn_close_pid</link>&#160;<phrase role="c_punctuation">()</phrase></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 id="glib-Spawning-Processes.other" role="other_proto">
<title role="other_proto.title">Types and Values</title>
<informaltable role="enum_members_table" pgwide="1" frame="none">
<tgroup cols="2">
<colspec colname="name" colwidth="150px"/>
<colspec colname="description"/>
<tbody>
<row><entry role="datatype_keyword">enum</entry><entry role="function_name"><link linkend="GSpawnError">GSpawnError</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-SPAWN-ERROR:CAPS">G_SPAWN_ERROR</link></entry></row>
<row><entry role="datatype_keyword">enum</entry><entry role="function_name"><link linkend="GSpawnFlags">GSpawnFlags</link></entry></row>
<row><entry role="define_keyword">#define</entry><entry role="function_name"><link linkend="G-SPAWN-EXIT-ERROR:CAPS">G_SPAWN_EXIT_ERROR</link></entry></row>

</tbody>
</tgroup>
</informaltable>
</refsect1>

<refsect1 id="glib-Spawning-Processes.includes"><title>Includes</title><synopsis>#include &lt;glib.h&gt;
</synopsis></refsect1>

<refsect1 id="glib-Spawning-Processes.description" role="desc">
<title role="desc.title">Description</title>
<para>GLib supports spawning of processes with an API that is more
convenient than the bare UNIX <link linkend="fork"><function>fork()</function></link> and <link linkend="exec"><function>exec()</function></link>.</para>
<para>The g_spawn family of functions has synchronous (<link linkend="g-spawn-sync"><function>g_spawn_sync()</function></link>)
and asynchronous variants (<link linkend="g-spawn-async"><function>g_spawn_async()</function></link>, <link linkend="g-spawn-async-with-pipes"><function>g_spawn_async_with_pipes()</function></link>),
as well as convenience variants that take a complete shell-like
commandline (<link linkend="g-spawn-command-line-sync"><function>g_spawn_command_line_sync()</function></link>, <link linkend="g-spawn-command-line-async"><function>g_spawn_command_line_async()</function></link>).</para>
<para>See <link linkend="GSubprocess"><type>GSubprocess</type></link> in GIO for a higher-level API that provides
stream interfaces for communication with child processes.</para>
<para>An example of using <link linkend="g-spawn-async-with-pipes"><function>g_spawn_async_with_pipes()</function></link>:</para>
<informalexample><programlisting role="example"><![CDATA[
const gchar * const argv[] = { "my-favourite-program", "--args", NULL };
gint child_stdout, child_stderr;
GPid child_pid;
g_autoptr(GError) error = NULL;

// Spawn child process.
g_spawn_async_with_pipes (NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL,
                          NULL, &child_pid, NULL, &child_stdout,
                          &child_stderr, &error);
if (error != NULL)
  {
    g_error ("Spawning child failed: %s", error->message);
    return;
  }

// Add a child watch function which will be called when the child process
// exits.
g_child_watch_add (child_pid, child_watch_cb, NULL);

// You could watch for output on @child_stdout and @child_stderr using
// #GUnixInputStream or #GIOChannel here.

static void
child_watch_cb (GPid     pid,
                gint     status,
                gpointer user_data)
{
  g_message ("Child %" G_PID_FORMAT " exited %s", pid,
             g_spawn_check_exit_status (status, NULL) ? "normally" : "abnormally");

  // Free any resources associated with the child here, such as I/O channels
  // on its stdout and stderr FDs. If you have no code to put in the
  // child_watch_cb() callback, you can remove it and the g_child_watch_add()
  // call, but you must also remove the G_SPAWN_DO_NOT_REAP_CHILD flag,
  // otherwise the child process will stay around as a zombie until this
  // process exits.

  g_spawn_close_pid (pid);
}
]]></programlisting></informalexample>
<para></para>

</refsect1>
<refsect1 id="glib-Spawning-Processes.functions_details" role="details">
<title role="details.title">Functions</title>
<refsect2 id="GSpawnChildSetupFunc" role="function">
<title>GSpawnChildSetupFunc&#160;()</title>
<indexterm zone="GSpawnChildSetupFunc"><primary sortas="SpawnChildSetupFunc">GSpawnChildSetupFunc</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
<phrase role="c_punctuation">(</phrase>*GSpawnChildSetupFunc<phrase role="c_punctuation">)</phrase> (<parameter><link linkend="gpointer"><type>gpointer</type></link> user_data</parameter>);</programlisting>
<para>Specifies the type of the setup function passed to <link linkend="g-spawn-async"><function>g_spawn_async()</function></link>,
<link linkend="g-spawn-sync"><function>g_spawn_sync()</function></link> and <link linkend="g-spawn-async-with-pipes"><function>g_spawn_async_with_pipes()</function></link>, which can, in very
limited ways, be used to affect the child's execution.</para>
<para>On POSIX platforms, the function is called in the child after GLib
has performed all the setup it plans to perform, but before calling
<link linkend="exec"><function>exec()</function></link>. Actions taken in this function will only affect the child,
not the parent.</para>
<para>On Windows, the function is called in the parent. Its usefulness on
Windows is thus questionable. In many cases executing the child setup
function in the parent can have ill effects, and you should be very
careful when porting software to Windows that uses child setup
functions.</para>
<para>However, even on POSIX, you are extremely limited in what you can
safely do from a <link linkend="GSpawnChildSetupFunc"><type>GSpawnChildSetupFunc</type></link>, because any mutexes that were
held by other threads in the parent process at the time of the <link linkend="fork"><function>fork()</function></link>
will still be locked in the child process, and they will never be
unlocked (since the threads that held them don't exist in the child).
POSIX allows only async-signal-safe functions (see signal(7)) to be
called in the child between <link linkend="fork"><function>fork()</function></link> and <link linkend="exec"><function>exec()</function></link>, which drastically limits
the usefulness of child setup functions.</para>
<para>In particular, it is not safe to call any function which may
call <link linkend="malloc"><function>malloc()</function></link>, which includes POSIX functions such as <link linkend="setenv"><function>setenv()</function></link>.
If you need to set up the child environment differently from
the parent, you should use <link linkend="g-get-environ"><function>g_get_environ()</function></link>, <link linkend="g-environ-setenv"><function>g_environ_setenv()</function></link>,
and <link linkend="g-environ-unsetenv"><function>g_environ_unsetenv()</function></link>, and then pass the complete environment
list to the <literal>g_spawn...</literal> function.</para>
<refsect3 id="GSpawnChildSetupFunc.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>user_data</para></entry>
<entry role="parameter_description"><para>user data to pass to the function. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>closure</acronym>]</emphasis></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="g-spawn-async-with-fds" role="function" condition="since:2.58">
<title>g_spawn_async_with_fds&#160;()</title>
<indexterm zone="g-spawn-async-with-fds" role="2.58"><primary sortas="spawn_async_with_fds">g_spawn_async_with_fds</primary></indexterm>
<programlisting language="C"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
g_spawn_async_with_fds (<parameter>const <link linkend="gchar"><type>gchar</type></link> *working_directory</parameter>,
                        <parameter><link linkend="gchar"><type>gchar</type></link> **argv</parameter>,
                        <parameter><link linkend="gchar"><type>gchar</type></link> **envp</parameter>,
                        <parameter><link linkend="GSpawnFlags"><type>GSpawnFlags</type></link> flags</parameter>,
                        <parameter><link linkend="GSpawnChildSetupFunc"><type>GSpawnChildSetupFunc</type></link> child_setup</parameter>,
                        <parameter><link linkend="gpointer"><type>gpointer</type></link> user_data</parameter>,
                        <parameter><link linkend="GPid"><type>GPid</type></link> *child_pid</parameter>,
                        <parameter><link linkend="gint"><type>gint</type></link> stdin_fd</parameter>,
                        <parameter><link linkend="gint"><type>gint</type></link> stdout_fd</parameter>,
                        <parameter><link linkend="gint"><type>gint</type></link> stderr_fd</parameter>,
                        <parameter><link linkend="GError"><type>GError</type></link> **error</parameter>);</programlisting>
<para>Identical to <link linkend="g-spawn-async-with-pipes"><function>g_spawn_async_with_pipes()</function></link> but instead of
creating pipes for the stdin/stdout/stderr, you can pass existing
file descriptors into this function through the <parameter>stdin_fd</parameter>
,
<parameter>stdout_fd</parameter>
 and <parameter>stderr_fd</parameter>
 parameters. The following <parameter>flags</parameter>

also have their behaviour slightly tweaked as a result:</para>
<para><link linkend="G-SPAWN-STDOUT-TO-DEV-NULL:CAPS"><literal>G_SPAWN_STDOUT_TO_DEV_NULL</literal></link> 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, <parameter>standard_output</parameter>
 must be -1.
<link linkend="G-SPAWN-STDERR-TO-DEV-NULL:CAPS"><literal>G_SPAWN_STDERR_TO_DEV_NULL</literal></link> 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, <parameter>standard_error</parameter>
 must be -1.
<link linkend="G-SPAWN-CHILD-INHERITS-STDIN:CAPS"><literal>G_SPAWN_CHILD_INHERITS_STDIN</literal></link> means that the child will inherit the parent's
standard input (by default, the child's standard input is attached to
/dev/null). If you use this flag, <parameter>standard_input</parameter>
 must be -1.</para>
<para>It is valid to pass the same fd in multiple parameters (e.g. you can pass
a single fd for both stdout and stderr).</para>
<refsect3 id="g-spawn-async-with-fds.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>working_directory</para></entry>
<entry role="parameter_description"><para>child's current working directory, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> to inherit parent's, in the GLib file name encoding. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>type</acronym> filename][<acronym>nullable</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>argv</para></entry>
<entry role="parameter_description"><para>child's argument vector, in the GLib file name encoding. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>array</acronym> zero-terminated=1]</emphasis></entry></row>
<row><entry role="parameter_name"><para>envp</para></entry>
<entry role="parameter_description"><para>child's environment, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> to inherit parent's, in the GLib file name encoding. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>array</acronym> zero-terminated=1][<acronym>nullable</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>flags</para></entry>
<entry role="parameter_description"><para>flags from <link linkend="GSpawnFlags"><type>GSpawnFlags</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>child_setup</para></entry>
<entry role="parameter_description"><para>function to run in the child just before <link linkend="exec"><function>exec()</function></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>scope async</acronym>][<acronym>nullable</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>user_data</para></entry>
<entry role="parameter_description"><para>user data for <parameter>child_setup</parameter>
. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>closure</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>child_pid</para></entry>
<entry role="parameter_description"><para>return location for child process ID, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>optional</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>stdin_fd</para></entry>
<entry role="parameter_description"><para>file descriptor to use for child's stdin, or -1</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>stdout_fd</para></entry>
<entry role="parameter_description"><para>file descriptor to use for child's stdout, or -1</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>stderr_fd</para></entry>
<entry role="parameter_description"><para>file descriptor to use for child's stderr, or -1</para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>error</para></entry>
<entry role="parameter_description"><para>return location for error</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-spawn-async-with-fds.returns" role="returns">
<title>Returns</title>
<para> <link linkend="TRUE:CAPS"><literal>TRUE</literal></link> on success, <link linkend="FALSE:CAPS"><literal>FALSE</literal></link> if an error was set</para>
</refsect3><para role="since">Since: <link linkend="api-index-2.58">2.58</link></para></refsect2>
<refsect2 id="g-spawn-async-with-pipes" role="function">
<title>g_spawn_async_with_pipes&#160;()</title>
<indexterm zone="g-spawn-async-with-pipes"><primary sortas="spawn_async_with_pipes">g_spawn_async_with_pipes</primary></indexterm>
<programlisting language="C"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
g_spawn_async_with_pipes (<parameter>const <link linkend="gchar"><type>gchar</type></link> *working_directory</parameter>,
                          <parameter><link linkend="gchar"><type>gchar</type></link> **argv</parameter>,
                          <parameter><link linkend="gchar"><type>gchar</type></link> **envp</parameter>,
                          <parameter><link linkend="GSpawnFlags"><type>GSpawnFlags</type></link> flags</parameter>,
                          <parameter><link linkend="GSpawnChildSetupFunc"><type>GSpawnChildSetupFunc</type></link> child_setup</parameter>,
                          <parameter><link linkend="gpointer"><type>gpointer</type></link> user_data</parameter>,
                          <parameter><link linkend="GPid"><type>GPid</type></link> *child_pid</parameter>,
                          <parameter><link linkend="gint"><type>gint</type></link> *standard_input</parameter>,
                          <parameter><link linkend="gint"><type>gint</type></link> *standard_output</parameter>,
                          <parameter><link linkend="gint"><type>gint</type></link> *standard_error</parameter>,
                          <parameter><link linkend="GError"><type>GError</type></link> **error</parameter>);</programlisting>
<para>Executes a child program asynchronously (your program will not
block waiting for the child to exit). The child program is
specified by the only argument that must be provided, <parameter>argv</parameter>
.
<parameter>argv</parameter>
 should be a <link linkend="NULL:CAPS"><literal>NULL</literal></link>-terminated array of strings, to be passed
as the argument vector for the child. The first string in <parameter>argv</parameter>

is of course the name of the program to execute. By default, the
name of the program must be a full path. If <parameter>flags</parameter>
 contains the
<link linkend="G-SPAWN-SEARCH-PATH:CAPS"><literal>G_SPAWN_SEARCH_PATH</literal></link> flag, the <literal>PATH</literal> environment variable is
used to search for the executable. If <parameter>flags</parameter>
 contains the
<link linkend="G-SPAWN-SEARCH-PATH-FROM-ENVP:CAPS"><literal>G_SPAWN_SEARCH_PATH_FROM_ENVP</literal></link> flag, the <literal>PATH</literal> variable from 
<parameter>envp</parameter>
 is used to search for the executable. If both the
<link linkend="G-SPAWN-SEARCH-PATH:CAPS"><literal>G_SPAWN_SEARCH_PATH</literal></link> and <link linkend="G-SPAWN-SEARCH-PATH-FROM-ENVP:CAPS"><literal>G_SPAWN_SEARCH_PATH_FROM_ENVP</literal></link> flags
are set, the <literal>PATH</literal> variable from <parameter>envp</parameter>
 takes precedence over
the environment variable.</para>
<para>If the program name is not a full path and <link linkend="G-SPAWN-SEARCH-PATH:CAPS"><literal>G_SPAWN_SEARCH_PATH</literal></link> flag is not
used, then the program will be run from the current directory (or
<parameter>working_directory</parameter>
, if specified); this might be unexpected or even
dangerous in some cases when the current directory is world-writable.</para>
<para>On Windows, note that all the string or string vector arguments to
this function and the other g_spawn*() functions are in UTF-8, the
GLib file name encoding. Unicode characters that are not part of
the system codepage passed in these arguments will be correctly
available in the spawned program only if it uses wide character API
to retrieve its command line. For C programs built with Microsoft's
tools it is enough to make the program have a <link linkend="wmain"><function>wmain()</function></link> instead of
<link linkend="main"><function>main()</function></link>. <link linkend="wmain"><function>wmain()</function></link> has a wide character argument vector as parameter.</para>
<para>At least currently, mingw doesn't support <link linkend="wmain"><function>wmain()</function></link>, so if you use
mingw to develop the spawned program, it should call
<link linkend="g-win32-get-command-line"><function>g_win32_get_command_line()</function></link> to get arguments in UTF-8.</para>
<para>On Windows the low-level child process creation API <link linkend="CreateProcess"><function>CreateProcess()</function></link>
doesn't use argument vectors, but a command line. The C runtime
library's spawn*() family of functions (which <link linkend="g-spawn-async-with-pipes"><function>g_spawn_async_with_pipes()</function></link>
eventually calls) paste the argument vector elements together into
a command line, and the C runtime startup code does a corresponding
reconstruction of an argument vector from the command line, to be
passed to <link linkend="main"><function>main()</function></link>. Complications arise when you have argument vector
elements that contain spaces or double quotes. The <literal>spawn*()</literal> functions
don't do any quoting or escaping, but on the other hand the startup
code does do unquoting and unescaping in order to enable receiving
arguments with embedded spaces or double quotes. To work around this
asymmetry, <link linkend="g-spawn-async-with-pipes"><function>g_spawn_async_with_pipes()</function></link> will do quoting and escaping on
argument vector elements that need it before calling the C runtime
<link linkend="spawn"><function>spawn()</function></link> function.</para>
<para>The returned <parameter>child_pid</parameter>
 on Windows is a handle to the child
process, not its identifier. Process handles and process
identifiers are different concepts on Windows.</para>
<para><parameter>envp</parameter>
 is a <link linkend="NULL:CAPS"><literal>NULL</literal></link>-terminated array of strings, where each string
has the form <literal>KEY=VALUE</literal>. This will become the child's environment.
If <parameter>envp</parameter>
 is <link linkend="NULL:CAPS"><literal>NULL</literal></link>, the child inherits its parent's environment.</para>
<para><parameter>flags</parameter>
 should be the bitwise OR of any flags you want to affect the
function's behaviour. The <link linkend="G-SPAWN-DO-NOT-REAP-CHILD:CAPS"><literal>G_SPAWN_DO_NOT_REAP_CHILD</literal></link> means that the
child will not automatically be reaped; you must use a child watch
(<link linkend="g-child-watch-add"><function>g_child_watch_add()</function></link>) to be notified about the death of the child process,
otherwise it will stay around as a zombie process until this process exits.
Eventually you must call <link linkend="g-spawn-close-pid"><function>g_spawn_close_pid()</function></link> on the <parameter>child_pid</parameter>
, in order to
free resources which may be associated with the child process. (On Unix,
using a child watch is equivalent to calling <link linkend="waitpid"><function>waitpid()</function></link> or handling
the <link linkend="SIGCHLD:CAPS"><literal>SIGCHLD</literal></link> signal manually. On Windows, calling <link linkend="g-spawn-close-pid"><function>g_spawn_close_pid()</function></link>
is equivalent to calling <link linkend="CloseHandle"><function>CloseHandle()</function></link> on the process handle returned
in <parameter>child_pid</parameter>
). See <link linkend="g-child-watch-add"><function>g_child_watch_add()</function></link>.</para>
<para>Open UNIX file descriptors marked as <literal>FD_CLOEXEC</literal> will be automatically
closed in the child process. <link linkend="G-SPAWN-LEAVE-DESCRIPTORS-OPEN:CAPS"><literal>G_SPAWN_LEAVE_DESCRIPTORS_OPEN</literal></link> means that
other open file descriptors will be inherited by the child; otherwise all
descriptors except stdin/stdout/stderr will be closed before calling <link linkend="exec"><function>exec()</function></link>
in the child. <link linkend="G-SPAWN-SEARCH-PATH:CAPS"><literal>G_SPAWN_SEARCH_PATH</literal></link> means that <parameter>argv</parameter>
[0] need not be an
absolute path, it will be looked for in the <literal>PATH</literal> environment
variable. <link linkend="G-SPAWN-SEARCH-PATH-FROM-ENVP:CAPS"><literal>G_SPAWN_SEARCH_PATH_FROM_ENVP</literal></link> means need not be an
absolute path, it will be looked for in the <literal>PATH</literal> variable from
<parameter>envp</parameter>
. If both <link linkend="G-SPAWN-SEARCH-PATH:CAPS"><literal>G_SPAWN_SEARCH_PATH</literal></link> and <link linkend="G-SPAWN-SEARCH-PATH-FROM-ENVP:CAPS"><literal>G_SPAWN_SEARCH_PATH_FROM_ENVP</literal></link>
are used, the value from <parameter>envp</parameter>
 takes precedence over the environment.
<link linkend="G-SPAWN-STDOUT-TO-DEV-NULL:CAPS"><literal>G_SPAWN_STDOUT_TO_DEV_NULL</literal></link> 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, <parameter>standard_output</parameter>
 must be <link linkend="NULL:CAPS"><literal>NULL</literal></link>.
<link linkend="G-SPAWN-STDERR-TO-DEV-NULL:CAPS"><literal>G_SPAWN_STDERR_TO_DEV_NULL</literal></link> 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, <parameter>standard_error</parameter>
 must be <link linkend="NULL:CAPS"><literal>NULL</literal></link>.
<link linkend="G-SPAWN-CHILD-INHERITS-STDIN:CAPS"><literal>G_SPAWN_CHILD_INHERITS_STDIN</literal></link> means that the child will inherit the parent's
standard input (by default, the child's standard input is attached to
<literal>/dev/null</literal>). If you use this flag, <parameter>standard_input</parameter>
 must be <link linkend="NULL:CAPS"><literal>NULL</literal></link>.
<link linkend="G-SPAWN-FILE-AND-ARGV-ZERO:CAPS"><literal>G_SPAWN_FILE_AND_ARGV_ZERO</literal></link> means that the first element of <parameter>argv</parameter>
 is
the file to execute, while the remaining elements are the actual
argument vector to pass to the file. Normally <link linkend="g-spawn-async-with-pipes"><function>g_spawn_async_with_pipes()</function></link>
uses <parameter>argv</parameter>
[0] as the file to execute, and passes all of <parameter>argv</parameter>
 to the child.</para>
<para><parameter>child_setup</parameter>
 and <parameter>user_data</parameter>
 are a function and user data. On POSIX
platforms, the function is called in the child after GLib has
performed all the setup it plans to perform (including creating
pipes, closing file descriptors, etc.) but before calling <link linkend="exec"><function>exec()</function></link>.
That is, <parameter>child_setup</parameter>
 is called just before calling <link linkend="exec"><function>exec()</function></link> in the
child. Obviously actions taken in this function will only affect
the child, not the parent.</para>
<para>On Windows, there is no separate <link linkend="fork"><function>fork()</function></link> and <link linkend="exec"><function>exec()</function></link> functionality.
Child processes are created and run with a single API call,
<link linkend="CreateProcess"><function>CreateProcess()</function></link>. There is no sensible thing <parameter>child_setup</parameter>

could be used for on Windows so it is ignored and not called.</para>
<para>If non-<link linkend="NULL:CAPS"><literal>NULL</literal></link>, <parameter>child_pid</parameter>
 will on Unix be filled with the child's
process ID. You can use the process ID to send signals to the child,
or to use <link linkend="g-child-watch-add"><function>g_child_watch_add()</function></link> (or <link linkend="waitpid"><function>waitpid()</function></link>) if you specified the
<link linkend="G-SPAWN-DO-NOT-REAP-CHILD:CAPS"><literal>G_SPAWN_DO_NOT_REAP_CHILD</literal></link> flag. On Windows, <parameter>child_pid</parameter>
 will be
filled with a handle to the child process only if you specified the
<link linkend="G-SPAWN-DO-NOT-REAP-CHILD:CAPS"><literal>G_SPAWN_DO_NOT_REAP_CHILD</literal></link> flag. You can then access the child
process using the Win32 API, for example wait for its termination
with the WaitFor*() functions, or examine its exit code with
<link linkend="GetExitCodeProcess"><function>GetExitCodeProcess()</function></link>. You should close the handle with <link linkend="CloseHandle"><function>CloseHandle()</function></link>
or <link linkend="g-spawn-close-pid"><function>g_spawn_close_pid()</function></link> when you no longer need it.</para>
<para>If non-<link linkend="NULL:CAPS"><literal>NULL</literal></link>, the <parameter>standard_input</parameter>
, <parameter>standard_output</parameter>
, <parameter>standard_error</parameter>

locations will be filled with file descriptors for writing to the child's
standard input or reading from its standard output or standard error.
The caller of <link linkend="g-spawn-async-with-pipes"><function>g_spawn_async_with_pipes()</function></link> must close these file descriptors
when they are no longer in use. If these parameters are <link linkend="NULL:CAPS"><literal>NULL</literal></link>, the
corresponding pipe won't be created.</para>
<para>If <parameter>standard_input</parameter>
 is <link linkend="NULL:CAPS"><literal>NULL</literal></link>, the child's standard input is attached to
<literal>/dev/null</literal> unless <link linkend="G-SPAWN-CHILD-INHERITS-STDIN:CAPS"><literal>G_SPAWN_CHILD_INHERITS_STDIN</literal></link> is set.</para>
<para>If <parameter>standard_error</parameter>
 is NULL, the child's standard error goes to the same 
location as the parent's standard error unless <link linkend="G-SPAWN-STDERR-TO-DEV-NULL:CAPS"><literal>G_SPAWN_STDERR_TO_DEV_NULL</literal></link> 
is set.</para>
<para>If <parameter>standard_output</parameter>
 is NULL, the child's standard output goes to the same 
location as the parent's standard output unless <link linkend="G-SPAWN-STDOUT-TO-DEV-NULL:CAPS"><literal>G_SPAWN_STDOUT_TO_DEV_NULL</literal></link> 
is set.</para>
<para><parameter>error</parameter>
 can be <link linkend="NULL:CAPS"><literal>NULL</literal></link> to ignore errors, or non-<link linkend="NULL:CAPS"><literal>NULL</literal></link> to report errors.
If an error is set, the function returns <link linkend="FALSE:CAPS"><literal>FALSE</literal></link>. Errors are reported
even if they occur in the child (for example if the executable in
<parameter>argv</parameter>
[0] is not found). Typically the <literal>message</literal> field of returned
errors should be displayed to users. Possible errors are those from
the <link linkend="G-SPAWN-ERROR:CAPS"><type>G_SPAWN_ERROR</type></link> domain.</para>
<para>If an error occurs, <parameter>child_pid</parameter>
, <parameter>standard_input</parameter>
, <parameter>standard_output</parameter>
,
and <parameter>standard_error</parameter>
 will not be filled with valid values.</para>
<para>If <parameter>child_pid</parameter>
 is not <link linkend="NULL:CAPS"><literal>NULL</literal></link> and an error does not occur then the returned
process reference must be closed using <link linkend="g-spawn-close-pid"><function>g_spawn_close_pid()</function></link>.</para>
<para>On modern UNIX platforms, GLib can use an efficient process launching
codepath driven internally by <link linkend="posix-spawn"><function>posix_spawn()</function></link>. This has the advantage of
avoiding the fork-time performance costs of cloning the parent process
address space, and avoiding associated memory overcommit checks that are
not relevant in the context of immediately executing a distinct process.
This optimized codepath will be used provided that the following conditions
are met:</para>
<orderedlist>
<listitem><para><link linkend="G-SPAWN-DO-NOT-REAP-CHILD:CAPS"><literal>G_SPAWN_DO_NOT_REAP_CHILD</literal></link> is set</para></listitem>
<listitem><para><link linkend="G-SPAWN-LEAVE-DESCRIPTORS-OPEN:CAPS"><literal>G_SPAWN_LEAVE_DESCRIPTORS_OPEN</literal></link> is set</para></listitem>
<listitem><para><link linkend="G-SPAWN-SEARCH-PATH-FROM-ENVP:CAPS"><literal>G_SPAWN_SEARCH_PATH_FROM_ENVP</literal></link> is not set</para></listitem>
<listitem><para><parameter>working_directory</parameter>
 is <link linkend="NULL:CAPS"><literal>NULL</literal></link></para></listitem>
<listitem><para><parameter>child_setup</parameter>
 is <link linkend="NULL:CAPS"><literal>NULL</literal></link></para></listitem>
<listitem>
<para>The program is of a recognised binary format, or has a shebang. Otherwise, GLib will have to execute the program through the shell, which is not done using the optimized codepath.</para>
</listitem>
</orderedlist>
<para>If you are writing a GTK+ application, and the program you are spawning is a
graphical application too, then to ensure that the spawned program opens its
windows on the right screen, you may want to use <link linkend="GdkAppLaunchContext"><type>GdkAppLaunchContext</type></link>,
<link linkend="GAppLaunchContext"><type>GAppLaunchContext</type></link>, or set the <link linkend="DISPLAY:CAPS"><literal>DISPLAY</literal></link> environment variable.</para>
<refsect3 id="g-spawn-async-with-pipes.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>working_directory</para></entry>
<entry role="parameter_description"><para>child's current working
directory, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> to inherit parent's, in the GLib file name encoding. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>type</acronym> filename][<acronym>nullable</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>argv</para></entry>
<entry role="parameter_description"><para>child's argument
vector, in the GLib file name encoding. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>array</acronym> zero-terminated=1][<acronym>element-type</acronym> filename]</emphasis></entry></row>
<row><entry role="parameter_name"><para>envp</para></entry>
<entry role="parameter_description"><para>child's environment, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> to inherit parent's, in the GLib file
name encoding. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>array</acronym> zero-terminated=1][<acronym>element-type</acronym> filename][<acronym>nullable</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>flags</para></entry>
<entry role="parameter_description"><para>flags from <link linkend="GSpawnFlags"><type>GSpawnFlags</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>child_setup</para></entry>
<entry role="parameter_description"><para>function to run in the child just before <link linkend="exec"><function>exec()</function></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>scope async</acronym>][<acronym>nullable</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>user_data</para></entry>
<entry role="parameter_description"><para>user data for <parameter>child_setup</parameter>
. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>closure</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>child_pid</para></entry>
<entry role="parameter_description"><para>return location for child process ID, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>optional</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>standard_input</para></entry>
<entry role="parameter_description"><para>return location for file descriptor to write to child's stdin, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>optional</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>standard_output</para></entry>
<entry role="parameter_description"><para>return location for file descriptor to read child's stdout, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>optional</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>standard_error</para></entry>
<entry role="parameter_description"><para>return location for file descriptor to read child's stderr, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>optional</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>error</para></entry>
<entry role="parameter_description"><para>return location for error</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-spawn-async-with-pipes.returns" role="returns">
<title>Returns</title>
<para> <link linkend="TRUE:CAPS"><literal>TRUE</literal></link> on success, <link linkend="FALSE:CAPS"><literal>FALSE</literal></link> if an error was set</para>
</refsect3></refsect2>
<refsect2 id="g-spawn-async" role="function">
<title>g_spawn_async&#160;()</title>
<indexterm zone="g-spawn-async"><primary sortas="spawn_async">g_spawn_async</primary></indexterm>
<programlisting language="C"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
g_spawn_async (<parameter>const <link linkend="gchar"><type>gchar</type></link> *working_directory</parameter>,
               <parameter><link linkend="gchar"><type>gchar</type></link> **argv</parameter>,
               <parameter><link linkend="gchar"><type>gchar</type></link> **envp</parameter>,
               <parameter><link linkend="GSpawnFlags"><type>GSpawnFlags</type></link> flags</parameter>,
               <parameter><link linkend="GSpawnChildSetupFunc"><type>GSpawnChildSetupFunc</type></link> child_setup</parameter>,
               <parameter><link linkend="gpointer"><type>gpointer</type></link> user_data</parameter>,
               <parameter><link linkend="GPid"><type>GPid</type></link> *child_pid</parameter>,
               <parameter><link linkend="GError"><type>GError</type></link> **error</parameter>);</programlisting>
<para>See <link linkend="g-spawn-async-with-pipes"><function>g_spawn_async_with_pipes()</function></link> for a full description; this function
simply calls the <link linkend="g-spawn-async-with-pipes"><function>g_spawn_async_with_pipes()</function></link> without any pipes.</para>
<para>You should call <link linkend="g-spawn-close-pid"><function>g_spawn_close_pid()</function></link> on the returned child process
reference when you don't need it any more.</para>
<para>If you are writing a GTK+ application, and the program you are spawning is a
graphical application too, then to ensure that the spawned program opens its
windows on the right screen, you may want to use <link linkend="GdkAppLaunchContext"><type>GdkAppLaunchContext</type></link>,
<link linkend="GAppLaunchContext"><type>GAppLaunchContext</type></link>, or set the <link linkend="DISPLAY:CAPS"><literal>DISPLAY</literal></link> environment variable.</para>
<para>Note that the returned <parameter>child_pid</parameter>
 on Windows is a handle to the child
process and not its identifier. Process handles and process identifiers
are different concepts on Windows.</para>
<refsect3 id="g-spawn-async.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>working_directory</para></entry>
<entry role="parameter_description"><para>child's current working
directory, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> to inherit parent's. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>type</acronym> filename][<acronym>nullable</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>argv</para></entry>
<entry role="parameter_description"><para>child's argument vector. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>array</acronym> zero-terminated=1][<acronym>element-type</acronym> filename]</emphasis></entry></row>
<row><entry role="parameter_name"><para>envp</para></entry>
<entry role="parameter_description"><para>child's environment, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> to inherit parent's. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>array</acronym> zero-terminated=1][<acronym>element-type</acronym> filename][<acronym>nullable</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>flags</para></entry>
<entry role="parameter_description"><para>flags from <link linkend="GSpawnFlags"><type>GSpawnFlags</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>child_setup</para></entry>
<entry role="parameter_description"><para>function to run in the child just before <link linkend="exec"><function>exec()</function></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>scope async</acronym>][<acronym>nullable</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>user_data</para></entry>
<entry role="parameter_description"><para>user data for <parameter>child_setup</parameter>
. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>closure</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>child_pid</para></entry>
<entry role="parameter_description"><para>return location for child process reference, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>optional</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>error</para></entry>
<entry role="parameter_description"><para>return location for error</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-spawn-async.returns" role="returns">
<title>Returns</title>
<para> <link linkend="TRUE:CAPS"><literal>TRUE</literal></link> on success, <link linkend="FALSE:CAPS"><literal>FALSE</literal></link> if error is set</para>
</refsect3></refsect2>
<refsect2 id="g-spawn-sync" role="function">
<title>g_spawn_sync&#160;()</title>
<indexterm zone="g-spawn-sync"><primary sortas="spawn_sync">g_spawn_sync</primary></indexterm>
<programlisting language="C"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
g_spawn_sync (<parameter>const <link linkend="gchar"><type>gchar</type></link> *working_directory</parameter>,
              <parameter><link linkend="gchar"><type>gchar</type></link> **argv</parameter>,
              <parameter><link linkend="gchar"><type>gchar</type></link> **envp</parameter>,
              <parameter><link linkend="GSpawnFlags"><type>GSpawnFlags</type></link> flags</parameter>,
              <parameter><link linkend="GSpawnChildSetupFunc"><type>GSpawnChildSetupFunc</type></link> child_setup</parameter>,
              <parameter><link linkend="gpointer"><type>gpointer</type></link> user_data</parameter>,
              <parameter><link linkend="gchar"><type>gchar</type></link> **standard_output</parameter>,
              <parameter><link linkend="gchar"><type>gchar</type></link> **standard_error</parameter>,
              <parameter><link linkend="gint"><type>gint</type></link> *exit_status</parameter>,
              <parameter><link linkend="GError"><type>GError</type></link> **error</parameter>);</programlisting>
<para>Executes a child synchronously (waits for the child to exit before returning).
All output from the child is stored in <parameter>standard_output</parameter>
 and <parameter>standard_error</parameter>
,
if those parameters are non-<link linkend="NULL:CAPS"><literal>NULL</literal></link>. Note that you must set the  
<link linkend="G-SPAWN-STDOUT-TO-DEV-NULL:CAPS"><literal>G_SPAWN_STDOUT_TO_DEV_NULL</literal></link> and <link linkend="G-SPAWN-STDERR-TO-DEV-NULL:CAPS"><literal>G_SPAWN_STDERR_TO_DEV_NULL</literal></link> flags when
passing <link linkend="NULL:CAPS"><literal>NULL</literal></link> for <parameter>standard_output</parameter>
 and <parameter>standard_error</parameter>
.</para>
<para>If <parameter>exit_status</parameter>
 is non-<link linkend="NULL:CAPS"><literal>NULL</literal></link>, the platform-specific exit status of
the child is stored there; see the documentation of
<link linkend="g-spawn-check-exit-status"><function>g_spawn_check_exit_status()</function></link> for how to use and interpret this.
Note that it is invalid to pass <link linkend="G-SPAWN-DO-NOT-REAP-CHILD:CAPS"><literal>G_SPAWN_DO_NOT_REAP_CHILD</literal></link> in
<parameter>flags</parameter>
, and on POSIX platforms, the same restrictions as for
<link linkend="g-child-watch-source-new"><function>g_child_watch_source_new()</function></link> apply.</para>
<para>If an error occurs, no data is returned in <parameter>standard_output</parameter>
,
<parameter>standard_error</parameter>
, or <parameter>exit_status</parameter>
.</para>
<para>This function calls <link linkend="g-spawn-async-with-pipes"><function>g_spawn_async_with_pipes()</function></link> internally; see that
function for full details on the other parameters and details on
how these functions work on Windows.</para>
<refsect3 id="g-spawn-sync.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>working_directory</para></entry>
<entry role="parameter_description"><para>child's current working
directory, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> to inherit parent's. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>type</acronym> filename][<acronym>nullable</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>argv</para></entry>
<entry role="parameter_description"><para>child's argument vector. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>array</acronym> zero-terminated=1][<acronym>element-type</acronym> filename]</emphasis></entry></row>
<row><entry role="parameter_name"><para>envp</para></entry>
<entry role="parameter_description"><para>child's environment, or <link linkend="NULL:CAPS"><literal>NULL</literal></link> to inherit parent's. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>array</acronym> zero-terminated=1][<acronym>element-type</acronym> filename][<acronym>nullable</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>flags</para></entry>
<entry role="parameter_description"><para>flags from <link linkend="GSpawnFlags"><type>GSpawnFlags</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>child_setup</para></entry>
<entry role="parameter_description"><para>function to run in the child just before <link linkend="exec"><function>exec()</function></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>scope async</acronym>][<acronym>nullable</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>user_data</para></entry>
<entry role="parameter_description"><para>user data for <parameter>child_setup</parameter>
. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>closure</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>standard_output</para></entry>
<entry role="parameter_description"><para>return location for child output, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>array</acronym> zero-terminated=1][<acronym>element-type</acronym> guint8][<acronym>optional</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>standard_error</para></entry>
<entry role="parameter_description"><para>return location for child error messages, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>array</acronym> zero-terminated=1][<acronym>element-type</acronym> guint8][<acronym>optional</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>exit_status</para></entry>
<entry role="parameter_description"><para>return location for child exit status, as returned by <link linkend="waitpid"><function>waitpid()</function></link>, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>optional</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>error</para></entry>
<entry role="parameter_description"><para>return location for error, or <link linkend="NULL:CAPS"><literal>NULL</literal></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-spawn-sync.returns" role="returns">
<title>Returns</title>
<para> <link linkend="TRUE:CAPS"><literal>TRUE</literal></link> on success, <link linkend="FALSE:CAPS"><literal>FALSE</literal></link> if an error was set</para>
</refsect3></refsect2>
<refsect2 id="g-spawn-check-exit-status" role="function" condition="since:2.34">
<title>g_spawn_check_exit_status&#160;()</title>
<indexterm zone="g-spawn-check-exit-status" role="2.34"><primary sortas="spawn_check_exit_status">g_spawn_check_exit_status</primary></indexterm>
<programlisting language="C"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
g_spawn_check_exit_status (<parameter><link linkend="gint"><type>gint</type></link> exit_status</parameter>,
                           <parameter><link linkend="GError"><type>GError</type></link> **error</parameter>);</programlisting>
<para>Set <parameter>error</parameter>
 if <parameter>exit_status</parameter>
 indicates the child exited abnormally
(e.g. with a nonzero exit code, or via a fatal signal).</para>
<para>The <link linkend="g-spawn-sync"><function>g_spawn_sync()</function></link> and <link linkend="g-child-watch-add"><function>g_child_watch_add()</function></link> family of APIs return an
exit status for subprocesses encoded in a platform-specific way.
On Unix, this is guaranteed to be in the same format <link linkend="waitpid"><function>waitpid()</function></link> returns,
and on Windows it is guaranteed to be the result of <link linkend="GetExitCodeProcess"><function>GetExitCodeProcess()</function></link>.</para>
<para>Prior to the introduction of this function in GLib 2.34, interpreting
<parameter>exit_status</parameter>
 required use of platform-specific APIs, which is problematic
for software using GLib as a cross-platform layer.</para>
<para>Additionally, many programs simply want to determine whether or not
the child exited successfully, and either propagate a <link linkend="GError"><type>GError</type></link> or
print a message to standard error. In that common case, this function
can be used. Note that the error message in <parameter>error</parameter>
 will contain
human-readable information about the exit status.</para>
<para>The <parameter>domain</parameter>
 and <parameter>code</parameter>
 of <parameter>error</parameter>
 have special semantics in the case
where the process has an "exit code", as opposed to being killed by
a signal. On Unix, this happens if <link linkend="WIFEXITED:CAPS"><function>WIFEXITED()</function></link> would be true of
<parameter>exit_status</parameter>
. On Windows, it is always the case.</para>
<para>The special semantics are that the actual exit code will be the
code set in <parameter>error</parameter>
, and the domain will be <link linkend="G-SPAWN-EXIT-ERROR:CAPS"><literal>G_SPAWN_EXIT_ERROR</literal></link>.
This allows you to differentiate between different exit codes.</para>
<para>If the process was terminated by some means other than an exit
status, the domain will be <link linkend="G-SPAWN-ERROR:CAPS"><literal>G_SPAWN_ERROR</literal></link>, and the code will be
<link linkend="G-SPAWN-ERROR-FAILED:CAPS"><literal>G_SPAWN_ERROR_FAILED</literal></link>.</para>
<para>This function just offers convenience; you can of course also check
the available platform via a macro such as <link linkend="G-OS-UNIX:CAPS"><literal>G_OS_UNIX</literal></link>, and use
<link linkend="WIFEXITED:CAPS"><function>WIFEXITED()</function></link> and <link linkend="WEXITSTATUS:CAPS"><function>WEXITSTATUS()</function></link> on <parameter>exit_status</parameter>
 directly. Do not attempt
to scan or parse the error message string; it may be translated and/or
change in future versions of GLib.</para>
<refsect3 id="g-spawn-check-exit-status.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>exit_status</para></entry>
<entry role="parameter_description"><para>An exit code as returned from <link linkend="g-spawn-sync"><function>g_spawn_sync()</function></link></para></entry>
<entry role="parameter_annotations"></entry></row>
<row><entry role="parameter_name"><para>error</para></entry>
<entry role="parameter_description"><para>a <link linkend="GError"><type>GError</type></link></para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-spawn-check-exit-status.returns" role="returns">
<title>Returns</title>
<para> <link linkend="TRUE:CAPS"><literal>TRUE</literal></link> if child exited successfully, <link linkend="FALSE:CAPS"><literal>FALSE</literal></link> otherwise (and
<parameter>error</parameter>
will be set)</para>
</refsect3><para role="since">Since: <link linkend="api-index-2.34">2.34</link></para></refsect2>
<refsect2 id="g-spawn-command-line-async" role="function">
<title>g_spawn_command_line_async&#160;()</title>
<indexterm zone="g-spawn-command-line-async"><primary sortas="spawn_command_line_async">g_spawn_command_line_async</primary></indexterm>
<programlisting language="C"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
g_spawn_command_line_async (<parameter>const <link linkend="gchar"><type>gchar</type></link> *command_line</parameter>,
                            <parameter><link linkend="GError"><type>GError</type></link> **error</parameter>);</programlisting>
<para>A simple version of <link linkend="g-spawn-async"><function>g_spawn_async()</function></link> that parses a command line with
<link linkend="g-shell-parse-argv"><function>g_shell_parse_argv()</function></link> and passes it to <link linkend="g-spawn-async"><function>g_spawn_async()</function></link>. Runs a
command line in the background. Unlike <link linkend="g-spawn-async"><function>g_spawn_async()</function></link>, the
<link linkend="G-SPAWN-SEARCH-PATH:CAPS"><literal>G_SPAWN_SEARCH_PATH</literal></link> flag is enabled, other flags are not. Note
that <link linkend="G-SPAWN-SEARCH-PATH:CAPS"><literal>G_SPAWN_SEARCH_PATH</literal></link> can have security implications, so
consider using <link linkend="g-spawn-async"><function>g_spawn_async()</function></link> directly if appropriate. Possible
errors are those from <link linkend="g-shell-parse-argv"><function>g_shell_parse_argv()</function></link> and <link linkend="g-spawn-async"><function>g_spawn_async()</function></link>.</para>
<para>The same concerns on Windows apply as for <link linkend="g-spawn-command-line-sync"><function>g_spawn_command_line_sync()</function></link>.</para>
<refsect3 id="g-spawn-command-line-async.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>command_line</para></entry>
<entry role="parameter_description"><para>a command line. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>type</acronym> filename]</emphasis></entry></row>
<row><entry role="parameter_name"><para>error</para></entry>
<entry role="parameter_description"><para>return location for errors</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-spawn-command-line-async.returns" role="returns">
<title>Returns</title>
<para> <link linkend="TRUE:CAPS"><literal>TRUE</literal></link> on success, <link linkend="FALSE:CAPS"><literal>FALSE</literal></link> if error is set</para>
</refsect3></refsect2>
<refsect2 id="g-spawn-command-line-sync" role="function">
<title>g_spawn_command_line_sync&#160;()</title>
<indexterm zone="g-spawn-command-line-sync"><primary sortas="spawn_command_line_sync">g_spawn_command_line_sync</primary></indexterm>
<programlisting language="C"><link linkend="gboolean"><returnvalue>gboolean</returnvalue></link>
g_spawn_command_line_sync (<parameter>const <link linkend="gchar"><type>gchar</type></link> *command_line</parameter>,
                           <parameter><link linkend="gchar"><type>gchar</type></link> **standard_output</parameter>,
                           <parameter><link linkend="gchar"><type>gchar</type></link> **standard_error</parameter>,
                           <parameter><link linkend="gint"><type>gint</type></link> *exit_status</parameter>,
                           <parameter><link linkend="GError"><type>GError</type></link> **error</parameter>);</programlisting>
<para>A simple version of <link linkend="g-spawn-sync"><function>g_spawn_sync()</function></link> with little-used parameters
removed, taking a command line instead of an argument vector.  See
<link linkend="g-spawn-sync"><function>g_spawn_sync()</function></link> for full details. <parameter>command_line</parameter>
 will be parsed by
<link linkend="g-shell-parse-argv"><function>g_shell_parse_argv()</function></link>. Unlike <link linkend="g-spawn-sync"><function>g_spawn_sync()</function></link>, the <link linkend="G-SPAWN-SEARCH-PATH:CAPS"><literal>G_SPAWN_SEARCH_PATH</literal></link> flag
is enabled. Note that <link linkend="G-SPAWN-SEARCH-PATH:CAPS"><literal>G_SPAWN_SEARCH_PATH</literal></link> can have security
implications, so consider using <link linkend="g-spawn-sync"><function>g_spawn_sync()</function></link> directly if
appropriate. Possible errors are those from <link linkend="g-spawn-sync"><function>g_spawn_sync()</function></link> and those
from <link linkend="g-shell-parse-argv"><function>g_shell_parse_argv()</function></link>.</para>
<para>If <parameter>exit_status</parameter>
 is non-<link linkend="NULL:CAPS"><literal>NULL</literal></link>, the platform-specific exit status of
the child is stored there; see the documentation of
<link linkend="g-spawn-check-exit-status"><function>g_spawn_check_exit_status()</function></link> for how to use and interpret this.</para>
<para>On Windows, please note the implications of <link linkend="g-shell-parse-argv"><function>g_shell_parse_argv()</function></link>
parsing <parameter>command_line</parameter>
. Parsing is done according to Unix shell rules, not 
Windows command interpreter rules.
Space is a separator, and backslashes are
special. Thus you cannot simply pass a <parameter>command_line</parameter>
 containing
canonical Windows paths, like "c:\program files\app\app.exe", as
the backslashes will be eaten, and the space will act as a
separator. You need to enclose such paths with single quotes, like
"'c:\program files\app\app.exe' 'e:\folder\argument.txt'".</para>
<refsect3 id="g-spawn-command-line-sync.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>command_line</para></entry>
<entry role="parameter_description"><para>a command line. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>type</acronym> filename]</emphasis></entry></row>
<row><entry role="parameter_name"><para>standard_output</para></entry>
<entry role="parameter_description"><para>return location for child output. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>array</acronym> zero-terminated=1][<acronym>element-type</acronym> guint8][<acronym>optional</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>standard_error</para></entry>
<entry role="parameter_description"><para>return location for child errors. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>array</acronym> zero-terminated=1][<acronym>element-type</acronym> guint8][<acronym>optional</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>exit_status</para></entry>
<entry role="parameter_description"><para>return location for child exit status, as returned by <link linkend="waitpid"><function>waitpid()</function></link>. </para></entry>
<entry role="parameter_annotations"><emphasis role="annotation">[<acronym>out</acronym>][<acronym>optional</acronym>]</emphasis></entry></row>
<row><entry role="parameter_name"><para>error</para></entry>
<entry role="parameter_description"><para>return location for errors</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3><refsect3 id="g-spawn-command-line-sync.returns" role="returns">
<title>Returns</title>
<para> <link linkend="TRUE:CAPS"><literal>TRUE</literal></link> on success, <link linkend="FALSE:CAPS"><literal>FALSE</literal></link> if an error was set</para>
</refsect3></refsect2>
<refsect2 id="g-spawn-close-pid" role="function">
<title>g_spawn_close_pid&#160;()</title>
<indexterm zone="g-spawn-close-pid"><primary sortas="spawn_close_pid">g_spawn_close_pid</primary></indexterm>
<programlisting language="C"><link linkend="void"><returnvalue>void</returnvalue></link>
g_spawn_close_pid (<parameter><link linkend="GPid"><type>GPid</type></link> pid</parameter>);</programlisting>
<para>On some platforms, notably Windows, the <link linkend="GPid"><type>GPid</type></link> type represents a resource
which must be closed to prevent resource leaking. <link linkend="g-spawn-close-pid"><function>g_spawn_close_pid()</function></link>
is provided for this purpose. It should be used on all platforms, even
though it doesn't do anything under UNIX.</para>
<refsect3 id="g-spawn-close-pid.parameters" role="parameters">
<title>Parameters</title>
<informaltable role="parameters_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="parameters_name" colwidth="150px"/>
<colspec colname="parameters_description"/>
<colspec colname="parameters_annotations" colwidth="200px"/>
<tbody>
<row><entry role="parameter_name"><para>pid</para></entry>
<entry role="parameter_description"><para>The process reference to close</para></entry>
<entry role="parameter_annotations"></entry></row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>

</refsect1>
<refsect1 id="glib-Spawning-Processes.other_details" role="details">
<title role="details.title">Types and Values</title>
<refsect2 id="GSpawnError" role="enum">
<title>enum GSpawnError</title>
<indexterm zone="GSpawnError"><primary sortas="SpawnError">GSpawnError</primary></indexterm>
<para>Error codes returned by spawning processes.</para>
<refsect3 id="GSpawnError.members" role="enum_members">
<title>Members</title>
<informaltable role="enum_members_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="enum_members_name" colwidth="300px"/>
<colspec colname="enum_members_description"/>
<colspec colname="enum_members_annotations" colwidth="200px"/>
<tbody>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-FORK:CAPS">G_SPAWN_ERROR_FORK</para></entry>
<entry role="enum_member_description"><para>Fork failed due to lack of memory.</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-READ:CAPS">G_SPAWN_ERROR_READ</para></entry>
<entry role="enum_member_description"><para>Read or select on pipes failed.</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-CHDIR:CAPS">G_SPAWN_ERROR_CHDIR</para></entry>
<entry role="enum_member_description"><para>Changing to working directory failed.</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-ACCES:CAPS">G_SPAWN_ERROR_ACCES</para></entry>
<entry role="enum_member_description"><para>execv() returned <literal>EACCES</literal></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-PERM:CAPS">G_SPAWN_ERROR_PERM</para></entry>
<entry role="enum_member_description"><para>execv() returned <literal>EPERM</literal></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-TOO-BIG:CAPS">G_SPAWN_ERROR_TOO_BIG</para></entry>
<entry role="enum_member_description"><para>execv() returned <literal>E2BIG</literal></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-2BIG:CAPS">G_SPAWN_ERROR_2BIG</para></entry>
<entry role="enum_member_description"><para>deprecated alias for <link linkend="G-SPAWN-ERROR-TOO-BIG:CAPS"><literal>G_SPAWN_ERROR_TOO_BIG</literal></link></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-NOEXEC:CAPS">G_SPAWN_ERROR_NOEXEC</para></entry>
<entry role="enum_member_description"><para>execv() returned <literal>ENOEXEC</literal></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-NAMETOOLONG:CAPS">G_SPAWN_ERROR_NAMETOOLONG</para></entry>
<entry role="enum_member_description"><para>execv() returned <literal>ENAMETOOLONG</literal></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-NOENT:CAPS">G_SPAWN_ERROR_NOENT</para></entry>
<entry role="enum_member_description"><para>execv() returned <literal>ENOENT</literal></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-NOMEM:CAPS">G_SPAWN_ERROR_NOMEM</para></entry>
<entry role="enum_member_description"><para>execv() returned <literal>ENOMEM</literal></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-NOTDIR:CAPS">G_SPAWN_ERROR_NOTDIR</para></entry>
<entry role="enum_member_description"><para>execv() returned <literal>ENOTDIR</literal></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-LOOP:CAPS">G_SPAWN_ERROR_LOOP</para></entry>
<entry role="enum_member_description"><para>execv() returned <literal>ELOOP</literal></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-TXTBUSY:CAPS">G_SPAWN_ERROR_TXTBUSY</para></entry>
<entry role="enum_member_description"><para>execv() returned <literal>ETXTBUSY</literal></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-IO:CAPS">G_SPAWN_ERROR_IO</para></entry>
<entry role="enum_member_description"><para>execv() returned <literal>EIO</literal></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-NFILE:CAPS">G_SPAWN_ERROR_NFILE</para></entry>
<entry role="enum_member_description"><para>execv() returned <literal>ENFILE</literal></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-MFILE:CAPS">G_SPAWN_ERROR_MFILE</para></entry>
<entry role="enum_member_description"><para>execv() returned <literal>EMFILE</literal></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-INVAL:CAPS">G_SPAWN_ERROR_INVAL</para></entry>
<entry role="enum_member_description"><para>execv() returned <literal>EINVAL</literal></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-ISDIR:CAPS">G_SPAWN_ERROR_ISDIR</para></entry>
<entry role="enum_member_description"><para>execv() returned <literal>EISDIR</literal></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-LIBBAD:CAPS">G_SPAWN_ERROR_LIBBAD</para></entry>
<entry role="enum_member_description"><para>execv() returned <literal>ELIBBAD</literal></para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-ERROR-FAILED:CAPS">G_SPAWN_ERROR_FAILED</para></entry>
<entry role="enum_member_description"><para>Some other fatal failure,
  <literal>error-&gt;message</literal> should explain.</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="G-SPAWN-ERROR:CAPS" role="macro">
<title>G_SPAWN_ERROR</title>
<indexterm zone="G-SPAWN-ERROR:CAPS"><primary sortas="SPAWN_ERROR">G_SPAWN_ERROR</primary></indexterm>
<programlisting language="C">#define G_SPAWN_ERROR g_spawn_error_quark ()
</programlisting>
<para>Error domain for spawning processes. Errors in this domain will
be from the <link linkend="GSpawnError"><type>GSpawnError</type></link> enumeration. See <link linkend="GError"><type>GError</type></link> for information on
error domains.</para>
</refsect2>
<refsect2 id="GSpawnFlags" role="enum">
<title>enum GSpawnFlags</title>
<indexterm zone="GSpawnFlags"><primary sortas="SpawnFlags">GSpawnFlags</primary></indexterm>
<para>Flags passed to <link linkend="g-spawn-sync"><function>g_spawn_sync()</function></link>, <link linkend="g-spawn-async"><function>g_spawn_async()</function></link> and <link linkend="g-spawn-async-with-pipes"><function>g_spawn_async_with_pipes()</function></link>.</para>
<refsect3 id="GSpawnFlags.members" role="enum_members">
<title>Members</title>
<informaltable role="enum_members_table" pgwide="1" frame="none">
<tgroup cols="3">
<colspec colname="enum_members_name" colwidth="300px"/>
<colspec colname="enum_members_description"/>
<colspec colname="enum_members_annotations" colwidth="200px"/>
<tbody>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-DEFAULT:CAPS">G_SPAWN_DEFAULT</para></entry>
<entry role="enum_member_description"><para>no flags, default behaviour</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-LEAVE-DESCRIPTORS-OPEN:CAPS">G_SPAWN_LEAVE_DESCRIPTORS_OPEN</para></entry>
<entry role="enum_member_description"><para>the parent's open file descriptors will
    be inherited by the child; otherwise all descriptors except stdin,
    stdout and stderr will be closed before calling <link linkend="exec"><function>exec()</function></link> in the child.</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-DO-NOT-REAP-CHILD:CAPS">G_SPAWN_DO_NOT_REAP_CHILD</para></entry>
<entry role="enum_member_description"><para>the child will not be automatically reaped;
    you must use <link linkend="g-child-watch-add"><function>g_child_watch_add()</function></link> yourself (or call <link linkend="waitpid"><function>waitpid()</function></link> or handle
    <literal>SIGCHLD</literal> yourself), or the child will become a zombie.</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-SEARCH-PATH:CAPS">G_SPAWN_SEARCH_PATH</para></entry>
<entry role="enum_member_description"><para><literal>argv[0]</literal> need not be an absolute path, it will be
    looked for in the user's <literal>PATH</literal>.</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-STDOUT-TO-DEV-NULL:CAPS">G_SPAWN_STDOUT_TO_DEV_NULL</para></entry>
<entry role="enum_member_description"><para>the child's standard output will be discarded,
    instead of going to the same location as the parent's standard output.</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-STDERR-TO-DEV-NULL:CAPS">G_SPAWN_STDERR_TO_DEV_NULL</para></entry>
<entry role="enum_member_description"><para>the child's standard error will be discarded.</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-CHILD-INHERITS-STDIN:CAPS">G_SPAWN_CHILD_INHERITS_STDIN</para></entry>
<entry role="enum_member_description"><para>the child will inherit the parent's standard
    input (by default, the child's standard input is attached to <literal>/dev/null</literal>).</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-FILE-AND-ARGV-ZERO:CAPS">G_SPAWN_FILE_AND_ARGV_ZERO</para></entry>
<entry role="enum_member_description"><para>the first element of <literal>argv</literal> is the file to
    execute, while the remaining elements are the actual argument vector
    to pass to the file. Normally <link linkend="g-spawn-async-with-pipes"><function>g_spawn_async_with_pipes()</function></link> uses <literal>argv[0]</literal>
    as the file to execute, and passes all of <literal>argv</literal> to the child.</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-SEARCH-PATH-FROM-ENVP:CAPS">G_SPAWN_SEARCH_PATH_FROM_ENVP</para></entry>
<entry role="enum_member_description"><para>if <literal>argv[0]</literal> is not an abolute path,
    it will be looked for in the <literal>PATH</literal> from the passed child environment.
    Since: 2.34</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
<row role="constant"><entry role="enum_member_name"><para id="G-SPAWN-CLOEXEC-PIPES:CAPS">G_SPAWN_CLOEXEC_PIPES</para></entry>
<entry role="enum_member_description"><para>create all pipes with the <literal>O_CLOEXEC</literal> flag set.
    Since: 2.40</para>
</entry>
<entry role="enum_member_annotations"></entry>
</row>
</tbody></tgroup></informaltable>
</refsect3></refsect2>
<refsect2 id="G-SPAWN-EXIT-ERROR:CAPS" role="macro">
<title>G_SPAWN_EXIT_ERROR</title>
<indexterm zone="G-SPAWN-EXIT-ERROR:CAPS"><primary sortas="SPAWN_EXIT_ERROR">G_SPAWN_EXIT_ERROR</primary></indexterm>
<programlisting language="C">#define G_SPAWN_EXIT_ERROR g_spawn_exit_error_quark ()
</programlisting>
<para>Error domain used by <link linkend="g-spawn-check-exit-status"><function>g_spawn_check_exit_status()</function></link>.  The code
will be the program exit code.</para>
</refsect2>

</refsect1>

</refentry>
