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

<refsynopsisdiv id="glib-Spawning-Processes.synopsis" role="synopsis">
<title role="synopsis.title">Synopsis</title>

<synopsis>

#include &lt;glib.h&gt;

enum                <link linkend="GSpawnError">GSpawnError</link>;
#define             <link linkend="G-SPAWN-ERROR--CAPS">G_SPAWN_ERROR</link>
enum                <link linkend="GSpawnFlags">GSpawnFlags</link>;
<link linkend="void">void</link>                (<link linkend="GSpawnChildSetupFunc">*GSpawnChildSetupFunc</link>)             (<link linkend="gpointer">gpointer</link> user_data);
<link linkend="gboolean">gboolean</link>            <link linkend="g-spawn-async-with-pipes">g_spawn_async_with_pipes</link>            (const <link linkend="gchar">gchar</link> *working_directory,
                                                         <link linkend="gchar">gchar</link> **argv,
                                                         <link linkend="gchar">gchar</link> **envp,
                                                         <link linkend="GSpawnFlags">GSpawnFlags</link> flags,
                                                         <link linkend="GSpawnChildSetupFunc">GSpawnChildSetupFunc</link> child_setup,
                                                         <link linkend="gpointer">gpointer</link> user_data,
                                                         <link linkend="GPid">GPid</link> *child_pid,
                                                         <link linkend="gint">gint</link> *standard_input,
                                                         <link linkend="gint">gint</link> *standard_output,
                                                         <link linkend="gint">gint</link> *standard_error,
                                                         <link linkend="GError">GError</link> **error);
<link linkend="gboolean">gboolean</link>            <link linkend="g-spawn-async">g_spawn_async</link>                       (const <link linkend="gchar">gchar</link> *working_directory,
                                                         <link linkend="gchar">gchar</link> **argv,
                                                         <link linkend="gchar">gchar</link> **envp,
                                                         <link linkend="GSpawnFlags">GSpawnFlags</link> flags,
                                                         <link linkend="GSpawnChildSetupFunc">GSpawnChildSetupFunc</link> child_setup,
                                                         <link linkend="gpointer">gpointer</link> user_data,
                                                         <link linkend="GPid">GPid</link> *child_pid,
                                                         <link linkend="GError">GError</link> **error);
<link linkend="gboolean">gboolean</link>            <link linkend="g-spawn-sync">g_spawn_sync</link>                        (const <link linkend="gchar">gchar</link> *working_directory,
                                                         <link linkend="gchar">gchar</link> **argv,
                                                         <link linkend="gchar">gchar</link> **envp,
                                                         <link linkend="GSpawnFlags">GSpawnFlags</link> flags,
                                                         <link linkend="GSpawnChildSetupFunc">GSpawnChildSetupFunc</link> child_setup,
                                                         <link linkend="gpointer">gpointer</link> user_data,
                                                         <link linkend="gchar">gchar</link> **standard_output,
                                                         <link linkend="gchar">gchar</link> **standard_error,
                                                         <link linkend="gint">gint</link> *exit_status,
                                                         <link linkend="GError">GError</link> **error);
<link linkend="gboolean">gboolean</link>            <link linkend="g-spawn-command-line-async">g_spawn_command_line_async</link>          (const <link linkend="gchar">gchar</link> *command_line,
                                                         <link linkend="GError">GError</link> **error);
<link linkend="gboolean">gboolean</link>            <link linkend="g-spawn-command-line-sync">g_spawn_command_line_sync</link>           (const <link linkend="gchar">gchar</link> *command_line,
                                                         <link linkend="gchar">gchar</link> **standard_output,
                                                         <link linkend="gchar">gchar</link> **standard_error,
                                                         <link linkend="gint">gint</link> *exit_status,
                                                         <link linkend="GError">GError</link> **error);
<link linkend="void">void</link>                <link linkend="g-spawn-close-pid">g_spawn_close_pid</link>                   (<link linkend="GPid">GPid</link> pid);
</synopsis>
</refsynopsisdiv>









<refsect1 id="glib-Spawning-Processes.description" role="desc">
<title role="desc.title">Description</title>
<para>
</para>
</refsect1>

<refsect1 id="glib-Spawning-Processes.details" role="details">
<title role="details.title">Details</title>
<refsect2 id="GSpawnError" role="enum">
<title>enum GSpawnError</title>
<indexterm zone="GSpawnError"><primary sortas="SpawnError">GSpawnError</primary></indexterm><programlisting>typedef enum
{
  G_SPAWN_ERROR_FORK,   /* fork failed due to lack of memory */
  G_SPAWN_ERROR_READ,   /* read or select on pipes failed */
  G_SPAWN_ERROR_CHDIR,  /* changing to working dir failed */
  G_SPAWN_ERROR_ACCES,  /* execv() returned EACCES */
  G_SPAWN_ERROR_PERM,   /* execv() returned EPERM */
  G_SPAWN_ERROR_2BIG,   /* execv() returned E2BIG */
  G_SPAWN_ERROR_NOEXEC, /* execv() returned ENOEXEC */
  G_SPAWN_ERROR_NAMETOOLONG, /* ""  "" ENAMETOOLONG */
  G_SPAWN_ERROR_NOENT,       /* ""  "" ENOENT */
  G_SPAWN_ERROR_NOMEM,       /* ""  "" ENOMEM */
  G_SPAWN_ERROR_NOTDIR,      /* ""  "" ENOTDIR */
  G_SPAWN_ERROR_LOOP,        /* ""  "" ELOOP   */
  G_SPAWN_ERROR_TXTBUSY,     /* ""  "" ETXTBUSY */
  G_SPAWN_ERROR_IO,          /* ""  "" EIO */
  G_SPAWN_ERROR_NFILE,       /* ""  "" ENFILE */
  G_SPAWN_ERROR_MFILE,       /* ""  "" EMFLE */
  G_SPAWN_ERROR_INVAL,       /* ""  "" EINVAL */
  G_SPAWN_ERROR_ISDIR,       /* ""  "" EISDIR */
  G_SPAWN_ERROR_LIBBAD,      /* ""  "" ELIBBAD */
  G_SPAWN_ERROR_FAILED       /* other fatal failure, error-&gt;message
                              * should explain
                              */
} GSpawnError;
</programlisting>
<para>
Error codes returned by spawning processes.
</para><variablelist role="enum">
<varlistentry id="G-SPAWN-ERROR-FORK--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_FORK</literal></term>
<listitem><simpara>Fork failed due to lack of memory.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-READ--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_READ</literal></term>
<listitem><simpara>Read or select on pipes failed.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-CHDIR--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_CHDIR</literal></term>
<listitem><simpara>Changing to working directory failed.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-ACCES--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_ACCES</literal></term>
<listitem><simpara><link linkend="execv"><function>execv()</function></link> returned <link linkend="EACCES--CAPS"><literal>EACCES</literal></link>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-PERM--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_PERM</literal></term>
<listitem><simpara><link linkend="execv"><function>execv()</function></link> returned <link linkend="EPERM--CAPS"><literal>EPERM</literal></link>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-2BIG--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_2BIG</literal></term>
<listitem><simpara><link linkend="execv"><function>execv()</function></link> returned <link linkend="E2BIG--CAPS"><literal>E2BIG</literal></link>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-NOEXEC--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_NOEXEC</literal></term>
<listitem><simpara><link linkend="execv"><function>execv()</function></link> returned <link linkend="ENOEXEC--CAPS"><literal>ENOEXEC</literal></link>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-NAMETOOLONG--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_NAMETOOLONG</literal></term>
<listitem><simpara><link linkend="execv"><function>execv()</function></link> returned <link linkend="ENAMETOOLONG--CAPS"><literal>ENAMETOOLONG</literal></link>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-NOENT--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_NOENT</literal></term>
<listitem><simpara><link linkend="execv"><function>execv()</function></link> returned <link linkend="ENOENT--CAPS"><literal>ENOENT</literal></link>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-NOMEM--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_NOMEM</literal></term>
<listitem><simpara><link linkend="execv"><function>execv()</function></link> returned <link linkend="ENOMEM--CAPS"><literal>ENOMEM</literal></link>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-NOTDIR--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_NOTDIR</literal></term>
<listitem><simpara><link linkend="execv"><function>execv()</function></link> returned <link linkend="ENOTDIR--CAPS"><literal>ENOTDIR</literal></link>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-LOOP--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_LOOP</literal></term>
<listitem><simpara><link linkend="execv"><function>execv()</function></link> returned <link linkend="ELOOP--CAPS"><literal>ELOOP</literal></link>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-TXTBUSY--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_TXTBUSY</literal></term>
<listitem><simpara><link linkend="execv"><function>execv()</function></link> returned <link linkend="ETXTBUSY--CAPS"><literal>ETXTBUSY</literal></link>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-IO--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_IO</literal></term>
<listitem><simpara><link linkend="execv"><function>execv()</function></link> returned <link linkend="EIO--CAPS"><literal>EIO</literal></link>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-NFILE--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_NFILE</literal></term>
<listitem><simpara><link linkend="execv"><function>execv()</function></link> returned <link linkend="ENFILE--CAPS"><literal>ENFILE</literal></link>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-MFILE--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_MFILE</literal></term>
<listitem><simpara><link linkend="execv"><function>execv()</function></link> returned <link linkend="EMFILE--CAPS"><literal>EMFILE</literal></link>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-INVAL--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_INVAL</literal></term>
<listitem><simpara><link linkend="execv"><function>execv()</function></link> returned <link linkend="EINVAL--CAPS"><literal>EINVAL</literal></link>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-ISDIR--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_ISDIR</literal></term>
<listitem><simpara><link linkend="execv"><function>execv()</function></link> returned <link linkend="EISDIR--CAPS"><literal>EISDIR</literal></link>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-LIBBAD--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_LIBBAD</literal></term>
<listitem><simpara><link linkend="execv"><function>execv()</function></link> returned <link linkend="ELIBBAD--CAPS"><literal>ELIBBAD</literal></link>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-ERROR-FAILED--CAPS" role="constant">
<term><literal>G_SPAWN_ERROR_FAILED</literal></term>
<listitem><simpara>Some other fatal failure, <literal>error-&gt;message</literal> should explain.
</simpara></listitem>
</varlistentry>
</variablelist></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>#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><programlisting>typedef enum
{
  G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1 &lt;&lt; 0,
  G_SPAWN_DO_NOT_REAP_CHILD      = 1 &lt;&lt; 1,
  /* look for argv[0] in the path i.e. use execvp() */
  G_SPAWN_SEARCH_PATH            = 1 &lt;&lt; 2,
  /* Dump output to /dev/null */
  G_SPAWN_STDOUT_TO_DEV_NULL     = 1 &lt;&lt; 3,
  G_SPAWN_STDERR_TO_DEV_NULL     = 1 &lt;&lt; 4,
  G_SPAWN_CHILD_INHERITS_STDIN   = 1 &lt;&lt; 5,
  G_SPAWN_FILE_AND_ARGV_ZERO     = 1 &lt;&lt; 6
} GSpawnFlags;
</programlisting>
<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><variablelist role="enum">
<varlistentry id="G-SPAWN-LEAVE-DESCRIPTORS-OPEN--CAPS" role="constant">
<term><literal>G_SPAWN_LEAVE_DESCRIPTORS_OPEN</literal></term>
<listitem><simpara>the parent's 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.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-DO-NOT-REAP-CHILD--CAPS" role="constant">
<term><literal>G_SPAWN_DO_NOT_REAP_CHILD</literal></term>
<listitem><simpara>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.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-SEARCH-PATH--CAPS" role="constant">
<term><literal>G_SPAWN_SEARCH_PATH</literal></term>
<listitem><simpara><literal>argv[0]</literal> need not be an absolute path, 
  it will be looked for in the user's <envar>PATH</envar>.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-STDOUT-TO-DEV-NULL--CAPS" role="constant">
<term><literal>G_SPAWN_STDOUT_TO_DEV_NULL</literal></term>
<listitem><simpara>the child's standard output will be discarded, 
  instead of going to the same location as the parent's standard output.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-STDERR-TO-DEV-NULL--CAPS" role="constant">
<term><literal>G_SPAWN_STDERR_TO_DEV_NULL</literal></term>
<listitem><simpara>the child's standard error will be discarded.
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-CHILD-INHERITS-STDIN--CAPS" role="constant">
<term><literal>G_SPAWN_CHILD_INHERITS_STDIN</literal></term>
<listitem><simpara>the child will inherit the parent's standard 
  input (by default, the child's standard input is attached to
  <filename>/dev/null</filename>).
</simpara></listitem>
</varlistentry>
<varlistentry id="G-SPAWN-FILE-AND-ARGV-ZERO--CAPS" role="constant">
<term><literal>G_SPAWN_FILE_AND_ARGV_ZERO</literal></term>
<listitem><simpara>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.
</simpara></listitem>
</varlistentry>
</variablelist></refsect2>
<refsect2 id="GSpawnChildSetupFunc" role="function">
<title>GSpawnChildSetupFunc ()</title>
<indexterm zone="GSpawnChildSetupFunc"><primary sortas="SpawnChildSetupFunc">GSpawnChildSetupFunc</primary></indexterm><programlisting><link linkend="void">void</link>                (*GSpawnChildSetupFunc)             (<link linkend="gpointer">gpointer</link> user_data);</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>. On POSIX platforms it
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>. On POSIX actions taken in this
function will thus only affect the child, not the parent.
</para>
<para>
Note that 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>
Also note that modifying the environment from the child setup function
may not have the intended effect, since it will get overridden by
a non-<link linkend="NULL--CAPS"><literal>NULL</literal></link> <parameter>env</parameter> argument to the <literal>g_spawn...</literal> functions.
</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><variablelist role="params">
<varlistentry><term><parameter>user_data</parameter>&#160;:</term>
<listitem><simpara>user data to pass to the function.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-spawn-async-with-pipes" role="function">
<title>g_spawn_async_with_pipes ()</title>
<indexterm zone="g-spawn-async-with-pipes"><primary sortas="spawn_async_with_pipes">g_spawn_async_with_pipes</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_spawn_async_with_pipes            (const <link linkend="gchar">gchar</link> *working_directory,
                                                         <link linkend="gchar">gchar</link> **argv,
                                                         <link linkend="gchar">gchar</link> **envp,
                                                         <link linkend="GSpawnFlags">GSpawnFlags</link> flags,
                                                         <link linkend="GSpawnChildSetupFunc">GSpawnChildSetupFunc</link> child_setup,
                                                         <link linkend="gpointer">gpointer</link> user_data,
                                                         <link linkend="GPid">GPid</link> *child_pid,
                                                         <link linkend="gint">gint</link> *standard_input,
                                                         <link linkend="gint">gint</link> *standard_output,
                                                         <link linkend="gint">gint</link> *standard_error,
                                                         <link linkend="GError">GError</link> **error);</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; the <envar>PATH</envar> shell variable 
will only be searched if you pass the <link linkend="G-SPAWN-SEARCH-PATH--CAPS"><literal>G_SPAWN_SEARCH_PATH</literal></link> flag.
</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 will have to call the
undocumented function <link linkend="wgetmainargs"><function>__wgetmainargs()</function></link> to get the wide character
argument vector and environment. See gspawn-win32-helper.c in the
GLib sources or init.c in the mingw runtime sources for a prototype
for that function. Alternatively, you can retrieve the Win32 system
level wide character command line passed to the spawned program
using the <link linkend="GetCommandLineW"><function>GetCommandLineW()</function></link> function.
</para>
<para>
On Windows the low-level child process creation API
<function><link linkend="CreateProcess"><function>CreateProcess()</function></link></function> doesn't use argument vectors,
but a command line. The C runtime library's
<function>spawn*()</function> 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 of double quotes. The
<function>spawn*()</function> 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
<link linkend="GChildWatch"><type>GChildWatch</type></link> source to be notified about the death of the child 
process. 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 <link linkend="GChildWatch"><type>GChildWatch</type></link> source 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>).
</para>
<para>
<link linkend="G-SPAWN-LEAVE-DESCRIPTORS-OPEN--CAPS"><literal>G_SPAWN_LEAVE_DESCRIPTORS_OPEN</literal></link> means that the parent's 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 <literal>argv[0]</literal> need not be an absolute path, it
will be looked for in the user's <envar>PATH</envar>. 
<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
/dev/null). 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 <function>WaitFor*()</function> 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 NULL, the child's standard input is attached to 
/dev/null 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 <literal>argv[0]</literal> 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>
<note><para>
If you are writing a GTK+ application, and the program you 
are spawning is a graphical application, too, then you may
want to use <link linkend="gdk-spawn-on-screen-with-pipes"><function>gdk_spawn_on_screen_with_pipes()</function></link> instead to ensure that 
the spawned program opens its windows on the right screen.
</para></note></para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>working_directory</parameter>&#160;:</term>
<listitem><simpara> child's current working directory, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to inherit parent's, in the GLib file name encoding
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>argv</parameter>&#160;:</term>
<listitem><simpara> child's argument vector, in the GLib file name encoding
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>envp</parameter>&#160;:</term>
<listitem><simpara> child's environment, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to inherit parent's, in the GLib file name encoding
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>flags</parameter>&#160;:</term>
<listitem><simpara> flags from <link linkend="GSpawnFlags"><type>GSpawnFlags</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>child_setup</parameter>&#160;:</term>
<listitem><simpara> function to run in the child just before <link linkend="exec"><function>exec()</function></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>user_data</parameter>&#160;:</term>
<listitem><simpara> user data for <parameter>child_setup</parameter>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>child_pid</parameter>&#160;:</term>
<listitem><simpara> return location for child process ID, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>standard_input</parameter>&#160;:</term>
<listitem><simpara> return location for file descriptor to write to child's stdin, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>standard_output</parameter>&#160;:</term>
<listitem><simpara> return location for file descriptor to read child's stdout, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>standard_error</parameter>&#160;:</term>
<listitem><simpara> return location for file descriptor to read child's stderr, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara> return location for error
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> on success, <link linkend="FALSE--CAPS"><literal>FALSE</literal></link> if an error was set
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-spawn-async" role="function">
<title>g_spawn_async ()</title>
<indexterm zone="g-spawn-async"><primary sortas="spawn_async">g_spawn_async</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_spawn_async                       (const <link linkend="gchar">gchar</link> *working_directory,
                                                         <link linkend="gchar">gchar</link> **argv,
                                                         <link linkend="gchar">gchar</link> **envp,
                                                         <link linkend="GSpawnFlags">GSpawnFlags</link> flags,
                                                         <link linkend="GSpawnChildSetupFunc">GSpawnChildSetupFunc</link> child_setup,
                                                         <link linkend="gpointer">gpointer</link> user_data,
                                                         <link linkend="GPid">GPid</link> *child_pid,
                                                         <link linkend="GError">GError</link> **error);</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>
<note><para>
If you are writing a GTK+ application, and the program you 
are spawning is a graphical application, too, then you may
want to use <link linkend="gdk-spawn-on-screen"><function>gdk_spawn_on_screen()</function></link> instead to ensure that 
the spawned program opens its windows on the right screen.
</para></note>
</para>
<para>
<note><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></note></para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>working_directory</parameter>&#160;:</term>
<listitem><simpara> child's current working directory, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to inherit parent's
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>argv</parameter>&#160;:</term>
<listitem><simpara> child's argument vector
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>envp</parameter>&#160;:</term>
<listitem><simpara> child's environment, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to inherit parent's
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>flags</parameter>&#160;:</term>
<listitem><simpara> flags from <link linkend="GSpawnFlags"><type>GSpawnFlags</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>child_setup</parameter>&#160;:</term>
<listitem><simpara> function to run in the child just before <link linkend="exec"><function>exec()</function></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>user_data</parameter>&#160;:</term>
<listitem><simpara> user data for <parameter>child_setup</parameter>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>child_pid</parameter>&#160;:</term>
<listitem><simpara> return location for child process reference, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara> return location for error
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> on success, <link linkend="FALSE--CAPS"><literal>FALSE</literal></link> if error is set
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-spawn-sync" role="function">
<title>g_spawn_sync ()</title>
<indexterm zone="g-spawn-sync"><primary sortas="spawn_sync">g_spawn_sync</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_spawn_sync                        (const <link linkend="gchar">gchar</link> *working_directory,
                                                         <link linkend="gchar">gchar</link> **argv,
                                                         <link linkend="gchar">gchar</link> **envp,
                                                         <link linkend="GSpawnFlags">GSpawnFlags</link> flags,
                                                         <link linkend="GSpawnChildSetupFunc">GSpawnChildSetupFunc</link> child_setup,
                                                         <link linkend="gpointer">gpointer</link> user_data,
                                                         <link linkend="gchar">gchar</link> **standard_output,
                                                         <link linkend="gchar">gchar</link> **standard_error,
                                                         <link linkend="gint">gint</link> *exit_status,
                                                         <link linkend="GError">GError</link> **error);</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>.
If <parameter>exit_status</parameter> is non-<link linkend="NULL--CAPS"><literal>NULL</literal></link>, the exit status of the child is stored
there as it would be returned by <link linkend="waitpid"><function>waitpid()</function></link>; standard UNIX macros such 
as <link linkend="WIFEXITED--CAPS"><function>WIFEXITED()</function></link> and <link linkend="WEXITSTATUS--CAPS"><function>WEXITSTATUS()</function></link> must be used to evaluate the exit status.
Note that this function call <link linkend="waitpid"><function>waitpid()</function></link> even if <parameter>exit_status</parameter> is <link linkend="NULL--CAPS"><literal>NULL</literal></link>, and
does not accept the <link linkend="G-SPAWN-DO-NOT-REAP-CHILD--CAPS"><literal>G_SPAWN_DO_NOT_REAP_CHILD</literal></link> flag.
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>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>working_directory</parameter>&#160;:</term>
<listitem><simpara> child's current working directory, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to inherit parent's
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>argv</parameter>&#160;:</term>
<listitem><simpara> child's argument vector
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>envp</parameter>&#160;:</term>
<listitem><simpara> child's environment, or <link linkend="NULL--CAPS"><literal>NULL</literal></link> to inherit parent's
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>flags</parameter>&#160;:</term>
<listitem><simpara> flags from <link linkend="GSpawnFlags"><type>GSpawnFlags</type></link> 
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>child_setup</parameter>&#160;:</term>
<listitem><simpara> function to run in the child just before <link linkend="exec"><function>exec()</function></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>user_data</parameter>&#160;:</term>
<listitem><simpara> user data for <parameter>child_setup</parameter>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>standard_output</parameter>&#160;:</term>
<listitem><simpara> return location for child output, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>standard_error</parameter>&#160;:</term>
<listitem><simpara> return location for child error messages, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>exit_status</parameter>&#160;:</term>
<listitem><simpara> 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>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara> return location for error, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> on success, <link linkend="FALSE--CAPS"><literal>FALSE</literal></link> if an error was set.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-spawn-command-line-async" role="function">
<title>g_spawn_command_line_async ()</title>
<indexterm zone="g-spawn-command-line-async"><primary sortas="spawn_command_line_async">g_spawn_command_line_async</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_spawn_command_line_async          (const <link linkend="gchar">gchar</link> *command_line,
                                                         <link linkend="GError">GError</link> **error);</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>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>command_line</parameter>&#160;:</term>
<listitem><simpara> a command line
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara> return location for errors
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> on success, <link linkend="FALSE--CAPS"><literal>FALSE</literal></link> if error is set.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-spawn-command-line-sync" role="function">
<title>g_spawn_command_line_sync ()</title>
<indexterm zone="g-spawn-command-line-sync"><primary sortas="spawn_command_line_sync">g_spawn_command_line_sync</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_spawn_command_line_sync           (const <link linkend="gchar">gchar</link> *command_line,
                                                         <link linkend="gchar">gchar</link> **standard_output,
                                                         <link linkend="gchar">gchar</link> **standard_error,
                                                         <link linkend="gint">gint</link> *exit_status,
                                                         <link linkend="GError">GError</link> **error);</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 exit status of the child is stored there as
it would be returned by <link linkend="waitpid"><function>waitpid()</function></link>; standard UNIX macros such as <link linkend="WIFEXITED--CAPS"><function>WIFEXITED()</function></link>
and <link linkend="WEXITSTATUS--CAPS"><function>WEXITSTATUS()</function></link> must be used to evaluate the exit status.
</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>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>command_line</parameter>&#160;:</term>
<listitem><simpara> a command line 
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>standard_output</parameter>&#160;:</term>
<listitem><simpara> return location for child output
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>standard_error</parameter>&#160;:</term>
<listitem><simpara> return location for child errors
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>exit_status</parameter>&#160;:</term>
<listitem><simpara> return location for child exit status, as returned by <link linkend="waitpid"><function>waitpid()</function></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter>&#160;:</term>
<listitem><simpara> return location for errors
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> on success, <link linkend="FALSE--CAPS"><literal>FALSE</literal></link> if an error was set
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-spawn-close-pid" role="function">
<title>g_spawn_close_pid ()</title>
<indexterm zone="g-spawn-close-pid"><primary sortas="spawn_close_pid">g_spawn_close_pid</primary></indexterm><programlisting><link linkend="void">void</link>                g_spawn_close_pid                   (<link linkend="GPid">GPid</link> pid);</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>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>pid</parameter>&#160;:</term>
<listitem><simpara> The process reference to close
</simpara></listitem></varlistentry>
</variablelist></refsect2>

</refsect1>




</refentry>
