1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
5
<title>Spawning Processes</title>
6
<meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
7
<link rel="start" href="index.html" title="GLib Reference Manual">
8
<link rel="up" href="glib-utilities.html" title="GLib Utilities">
9
<link rel="prev" href="glib-Timers.html" title="Timers">
10
<link rel="next" href="glib-File-Utilities.html" title="File Utilities">
11
<meta name="generator" content="GTK-Doc V1.7 (XML mode)">
12
<link rel="stylesheet" href="style.css" type="text/css">
13
<link rel="chapter" href="glib.html" title="GLib Overview">
14
<link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals">
15
<link rel="chapter" href="glib-core.html" title="GLib Core Application Support">
16
<link rel="chapter" href="glib-utilities.html" title="GLib Utilities">
17
<link rel="chapter" href="glib-data-types.html" title="GLib Data Types">
18
<link rel="chapter" href="tools.html" title="GLib Tools">
19
<link rel="index" href="ix01.html" title="Index">
20
<link rel="index" href="ix02.html" title="Index of deprecated symbols">
21
<link rel="index" href="ix03.html" title="Index of new symbols in 2.2">
22
<link rel="index" href="ix04.html" title="Index of new symbols in 2.4">
23
<link rel="index" href="ix05.html" title="Index of new symbols in 2.6">
24
<link rel="index" href="ix06.html" title="Index of new symbols in 2.8">
25
<link rel="index" href="ix07.html" title="Index of new symbols in 2.10">
26
<link rel="index" href="ix08.html" title="Index of new symbols in 2.12">
28
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
29
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
31
<td><a accesskey="p" href="glib-Timers.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
32
<td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
33
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
34
<th width="100%" align="center">GLib Reference Manual</th>
35
<td><a accesskey="n" href="glib-File-Utilities.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
37
<tr><td colspan="5" class="shortcuts"><nobr><a href="#id2945417" class="shortcut">Top</a>
39
<a href="#id2945892" class="shortcut">Description</a></nobr></td></tr>
41
<div class="refentry" lang="en">
42
<a name="glib-Spawning-Processes"></a><div class="titlepage"></div>
43
<div class="refnamediv"><table width="100%"><tr>
46
<a name="id2945417"></a><span class="refentrytitle">Spawning Processes</span>
48
<p>Spawning Processes — process launching with <code class="function"><code class="function">fork()</code></code>/<code class="function"><code class="function">exec()</code></code>.</p>
50
<td valign="top" align="right"></td>
52
<div class="refsynopsisdiv">
54
<pre class="synopsis">
56
#include <glib.h>
59
enum <a href="glib-Spawning-Processes.html#GSpawnError">GSpawnError</a>;
60
#define <a href="glib-Spawning-Processes.html#G-SPAWN-ERROR:CAPS">G_SPAWN_ERROR</a>
61
enum <a href="glib-Spawning-Processes.html#GSpawnFlags">GSpawnFlags</a>;
62
void (<a href="glib-Spawning-Processes.html#GSpawnChildSetupFunc">*GSpawnChildSetupFunc</a>) (<a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);
63
<a href="glib-Basic-Types.html#gboolean">gboolean</a> <a href="glib-Spawning-Processes.html#g-spawn-async-with-pipes">g_spawn_async_with_pipes</a> (const <a href="glib-Basic-Types.html#gchar">gchar</a> *working_directory,
64
<a href="glib-Basic-Types.html#gchar">gchar</a> **argv,
65
<a href="glib-Basic-Types.html#gchar">gchar</a> **envp,
66
<a href="glib-Spawning-Processes.html#GSpawnFlags">GSpawnFlags</a> flags,
67
<a href="glib-Spawning-Processes.html#GSpawnChildSetupFunc">GSpawnChildSetupFunc</a> child_setup,
68
<a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data,
69
<a href="glib-The-Main-Event-Loop.html#GPid">GPid</a> *child_pid,
70
<a href="glib-Basic-Types.html#gint">gint</a> *standard_input,
71
<a href="glib-Basic-Types.html#gint">gint</a> *standard_output,
72
<a href="glib-Basic-Types.html#gint">gint</a> *standard_error,
73
<a href="glib-Error-Reporting.html#GError">GError</a> **error);
74
<a href="glib-Basic-Types.html#gboolean">gboolean</a> <a href="glib-Spawning-Processes.html#g-spawn-async">g_spawn_async</a> (const <a href="glib-Basic-Types.html#gchar">gchar</a> *working_directory,
75
<a href="glib-Basic-Types.html#gchar">gchar</a> **argv,
76
<a href="glib-Basic-Types.html#gchar">gchar</a> **envp,
77
<a href="glib-Spawning-Processes.html#GSpawnFlags">GSpawnFlags</a> flags,
78
<a href="glib-Spawning-Processes.html#GSpawnChildSetupFunc">GSpawnChildSetupFunc</a> child_setup,
79
<a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data,
80
<a href="glib-The-Main-Event-Loop.html#GPid">GPid</a> *child_pid,
81
<a href="glib-Error-Reporting.html#GError">GError</a> **error);
82
<a href="glib-Basic-Types.html#gboolean">gboolean</a> <a href="glib-Spawning-Processes.html#g-spawn-sync">g_spawn_sync</a> (const <a href="glib-Basic-Types.html#gchar">gchar</a> *working_directory,
83
<a href="glib-Basic-Types.html#gchar">gchar</a> **argv,
84
<a href="glib-Basic-Types.html#gchar">gchar</a> **envp,
85
<a href="glib-Spawning-Processes.html#GSpawnFlags">GSpawnFlags</a> flags,
86
<a href="glib-Spawning-Processes.html#GSpawnChildSetupFunc">GSpawnChildSetupFunc</a> child_setup,
87
<a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data,
88
<a href="glib-Basic-Types.html#gchar">gchar</a> **standard_output,
89
<a href="glib-Basic-Types.html#gchar">gchar</a> **standard_error,
90
<a href="glib-Basic-Types.html#gint">gint</a> *exit_status,
91
<a href="glib-Error-Reporting.html#GError">GError</a> **error);
92
<a href="glib-Basic-Types.html#gboolean">gboolean</a> <a href="glib-Spawning-Processes.html#g-spawn-command-line-async">g_spawn_command_line_async</a> (const <a href="glib-Basic-Types.html#gchar">gchar</a> *command_line,
93
<a href="glib-Error-Reporting.html#GError">GError</a> **error);
94
<a href="glib-Basic-Types.html#gboolean">gboolean</a> <a href="glib-Spawning-Processes.html#g-spawn-command-line-sync">g_spawn_command_line_sync</a> (const <a href="glib-Basic-Types.html#gchar">gchar</a> *command_line,
95
<a href="glib-Basic-Types.html#gchar">gchar</a> **standard_output,
96
<a href="glib-Basic-Types.html#gchar">gchar</a> **standard_error,
97
<a href="glib-Basic-Types.html#gint">gint</a> *exit_status,
98
<a href="glib-Error-Reporting.html#GError">GError</a> **error);
99
void <a href="glib-Spawning-Processes.html#g-spawn-close-pid">g_spawn_close_pid</a> (<a href="glib-The-Main-Event-Loop.html#GPid">GPid</a> pid);
103
<div class="refsect1" lang="en">
104
<a name="id2945892"></a><h2>Description</h2>
109
<div class="refsect1" lang="en">
110
<a name="id2945907"></a><h2>Details</h2>
111
<div class="refsect2" lang="en">
112
<a name="id2945917"></a><h3>
113
<a name="GSpawnError"></a>enum GSpawnError</h3>
114
<a class="indexterm" name="id2945930"></a><pre class="programlisting">typedef enum
116
G_SPAWN_ERROR_FORK, /* fork failed due to lack of memory */
117
G_SPAWN_ERROR_READ, /* read or select on pipes failed */
118
G_SPAWN_ERROR_CHDIR, /* changing to working dir failed */
119
G_SPAWN_ERROR_ACCES, /* execv() returned EACCES */
120
G_SPAWN_ERROR_PERM, /* execv() returned EPERM */
121
G_SPAWN_ERROR_2BIG, /* execv() returned E2BIG */
122
G_SPAWN_ERROR_NOEXEC, /* execv() returned ENOEXEC */
123
G_SPAWN_ERROR_NAMETOOLONG, /* "" "" ENAMETOOLONG */
124
G_SPAWN_ERROR_NOENT, /* "" "" ENOENT */
125
G_SPAWN_ERROR_NOMEM, /* "" "" ENOMEM */
126
G_SPAWN_ERROR_NOTDIR, /* "" "" ENOTDIR */
127
G_SPAWN_ERROR_LOOP, /* "" "" ELOOP */
128
G_SPAWN_ERROR_TXTBUSY, /* "" "" ETXTBUSY */
129
G_SPAWN_ERROR_IO, /* "" "" EIO */
130
G_SPAWN_ERROR_NFILE, /* "" "" ENFILE */
131
G_SPAWN_ERROR_MFILE, /* "" "" EMFLE */
132
G_SPAWN_ERROR_INVAL, /* "" "" EINVAL */
133
G_SPAWN_ERROR_ISDIR, /* "" "" EISDIR */
134
G_SPAWN_ERROR_LIBBAD, /* "" "" ELIBBAD */
135
G_SPAWN_ERROR_FAILED /* other fatal failure, error->message
141
Error codes returned by spawning processes.
143
<div class="variablelist"><table border="0">
144
<col align="left" valign="top">
147
<td><span class="term"><a name="G-SPAWN-ERROR-FORK:CAPS"></a><code class="literal">G_SPAWN_ERROR_FORK</code></span></td>
148
<td>Fork failed due to lack of memory.
152
<td><span class="term"><a name="G-SPAWN-ERROR-READ:CAPS"></a><code class="literal">G_SPAWN_ERROR_READ</code></span></td>
153
<td>Read or select on pipes failed.
157
<td><span class="term"><a name="G-SPAWN-ERROR-CHDIR:CAPS"></a><code class="literal">G_SPAWN_ERROR_CHDIR</code></span></td>
158
<td>Changing to working directory failed.
162
<td><span class="term"><a name="G-SPAWN-ERROR-ACCES:CAPS"></a><code class="literal">G_SPAWN_ERROR_ACCES</code></span></td>
164
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">EACCES</code>.
168
<td><span class="term"><a name="G-SPAWN-ERROR-PERM:CAPS"></a><code class="literal">G_SPAWN_ERROR_PERM</code></span></td>
170
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">EPERM</code>.
174
<td><span class="term"><a name="G-SPAWN-ERROR-2BIG:CAPS"></a><code class="literal">G_SPAWN_ERROR_2BIG</code></span></td>
176
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">E2BIG</code>.
180
<td><span class="term"><a name="G-SPAWN-ERROR-NOEXEC:CAPS"></a><code class="literal">G_SPAWN_ERROR_NOEXEC</code></span></td>
182
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ENOEXEC</code>.
186
<td><span class="term"><a name="G-SPAWN-ERROR-NAMETOOLONG:CAPS"></a><code class="literal">G_SPAWN_ERROR_NAMETOOLONG</code></span></td>
188
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ENAMETOOLONG</code>.
192
<td><span class="term"><a name="G-SPAWN-ERROR-NOENT:CAPS"></a><code class="literal">G_SPAWN_ERROR_NOENT</code></span></td>
194
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ENOENT</code>.
198
<td><span class="term"><a name="G-SPAWN-ERROR-NOMEM:CAPS"></a><code class="literal">G_SPAWN_ERROR_NOMEM</code></span></td>
200
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ENOMEM</code>.
204
<td><span class="term"><a name="G-SPAWN-ERROR-NOTDIR:CAPS"></a><code class="literal">G_SPAWN_ERROR_NOTDIR</code></span></td>
206
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ENOTDIR</code>.
210
<td><span class="term"><a name="G-SPAWN-ERROR-LOOP:CAPS"></a><code class="literal">G_SPAWN_ERROR_LOOP</code></span></td>
212
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ELOOP</code>.
216
<td><span class="term"><a name="G-SPAWN-ERROR-TXTBUSY:CAPS"></a><code class="literal">G_SPAWN_ERROR_TXTBUSY</code></span></td>
218
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ETXTBUSY</code>.
222
<td><span class="term"><a name="G-SPAWN-ERROR-IO:CAPS"></a><code class="literal">G_SPAWN_ERROR_IO</code></span></td>
224
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">EIO</code>.
228
<td><span class="term"><a name="G-SPAWN-ERROR-NFILE:CAPS"></a><code class="literal">G_SPAWN_ERROR_NFILE</code></span></td>
230
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ENFILE</code>.
234
<td><span class="term"><a name="G-SPAWN-ERROR-MFILE:CAPS"></a><code class="literal">G_SPAWN_ERROR_MFILE</code></span></td>
236
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">EMFILE</code>.
240
<td><span class="term"><a name="G-SPAWN-ERROR-INVAL:CAPS"></a><code class="literal">G_SPAWN_ERROR_INVAL</code></span></td>
242
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">EINVAL</code>.
246
<td><span class="term"><a name="G-SPAWN-ERROR-ISDIR:CAPS"></a><code class="literal">G_SPAWN_ERROR_ISDIR</code></span></td>
248
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">EISDIR</code>.
252
<td><span class="term"><a name="G-SPAWN-ERROR-LIBBAD:CAPS"></a><code class="literal">G_SPAWN_ERROR_LIBBAD</code></span></td>
254
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ELIBBAD</code>.
258
<td><span class="term"><a name="G-SPAWN-ERROR-FAILED:CAPS"></a><code class="literal">G_SPAWN_ERROR_FAILED</code></span></td>
259
<td>Some other fatal failure, <code class="literal">error->message</code> should explain.
267
<div class="refsect2" lang="en">
268
<a name="id2946826"></a><h3>
269
<a name="G-SPAWN-ERROR:CAPS"></a>G_SPAWN_ERROR</h3>
270
<a class="indexterm" name="id2946839"></a><pre class="programlisting">#define G_SPAWN_ERROR g_spawn_error_quark ()
273
Error domain for spawning processes. Errors in this domain will
274
be from the <a href="glib-Spawning-Processes.html#GSpawnError"><span class="type">GSpawnError</span></a> enumeration. See <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for information on
279
<div class="refsect2" lang="en">
280
<a name="id2946872"></a><h3>
281
<a name="GSpawnFlags"></a>enum GSpawnFlags</h3>
282
<a class="indexterm" name="id2946884"></a><pre class="programlisting">typedef enum
284
G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1 << 0,
285
G_SPAWN_DO_NOT_REAP_CHILD = 1 << 1,
286
/* look for argv[0] in the path i.e. use execvp() */
287
G_SPAWN_SEARCH_PATH = 1 << 2,
288
/* Dump output to /dev/null */
289
G_SPAWN_STDOUT_TO_DEV_NULL = 1 << 3,
290
G_SPAWN_STDERR_TO_DEV_NULL = 1 << 4,
291
G_SPAWN_CHILD_INHERITS_STDIN = 1 << 5,
292
G_SPAWN_FILE_AND_ARGV_ZERO = 1 << 6
296
Flags passed to <a href="glib-Spawning-Processes.html#g-spawn-sync"><code class="function">g_spawn_sync()</code></a>, <a href="glib-Spawning-Processes.html#g-spawn-async"><code class="function">g_spawn_async()</code></a> and <a href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a>.
298
<div class="variablelist"><table border="0">
299
<col align="left" valign="top">
302
<td><span class="term"><a name="G-SPAWN-LEAVE-DESCRIPTORS-OPEN:CAPS"></a><code class="literal">G_SPAWN_LEAVE_DESCRIPTORS_OPEN</code></span></td>
303
<td>the parent's open file descriptors will be
304
inherited by the child; otherwise all descriptors except stdin/stdout/stderr
305
will be closed before calling <code class="function"><code class="function">exec()</code></code> in the child.
309
<td><span class="term"><a name="G-SPAWN-DO-NOT-REAP-CHILD:CAPS"></a><code class="literal">G_SPAWN_DO_NOT_REAP_CHILD</code></span></td>
310
<td>the child will not be automatically reaped; you
311
must call <code class="function"><code class="function">waitpid()</code></code> or handle <code class="literal">SIGCHLD</code>
312
yourself, or the child will become a zombie.
316
<td><span class="term"><a name="G-SPAWN-SEARCH-PATH:CAPS"></a><code class="literal">G_SPAWN_SEARCH_PATH</code></span></td>
318
<code class="literal">argv[0]</code> need not be an absolute path,
319
it will be looked for in the user's <code class="envar">PATH</code>.
323
<td><span class="term"><a name="G-SPAWN-STDOUT-TO-DEV-NULL:CAPS"></a><code class="literal">G_SPAWN_STDOUT_TO_DEV_NULL</code></span></td>
324
<td>the child's standad output will be discarded,
325
instead of going to the same location as the parent's standard output.
329
<td><span class="term"><a name="G-SPAWN-STDERR-TO-DEV-NULL:CAPS"></a><code class="literal">G_SPAWN_STDERR_TO_DEV_NULL</code></span></td>
330
<td>the child's standard error will be discarded.
334
<td><span class="term"><a name="G-SPAWN-CHILD-INHERITS-STDIN:CAPS"></a><code class="literal">G_SPAWN_CHILD_INHERITS_STDIN</code></span></td>
335
<td>the child will inherit the parent's standard
336
input (by default, the child's standard input is attached to
337
<code class="filename">/dev/null</code>).
341
<td><span class="term"><a name="G-SPAWN-FILE-AND-ARGV-ZERO:CAPS"></a><code class="literal">G_SPAWN_FILE_AND_ARGV_ZERO</code></span></td>
342
<td>the first element of <code class="literal">argv</code> is
343
the file to execute, while the remaining elements are the actual argument
344
vector to pass to the file. Normally <a href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a> uses
345
<code class="literal">argv[0]</code> as the file to execute, and passes all of
346
<code class="literal">argv</code> to the child.
354
<div class="refsect2" lang="en">
355
<a name="id2947198"></a><h3>
356
<a name="GSpawnChildSetupFunc"></a>GSpawnChildSetupFunc ()</h3>
357
<a class="indexterm" name="id2947212"></a><pre class="programlisting">void (*GSpawnChildSetupFunc) (<a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);</pre>
359
Specifies the type of the setup function passed to <a href="glib-Spawning-Processes.html#g-spawn-async"><code class="function">g_spawn_async()</code></a>,
360
<a href="glib-Spawning-Processes.html#g-spawn-sync"><code class="function">g_spawn_sync()</code></a> and <a href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a>. On POSIX platforms it
361
is called in the child after GLib has performed all the setup it plans
362
to perform but before calling <code class="function"><code class="function">exec()</code></code>. On POSIX
363
actions taken in this function will thus only affect the child, not
367
On Windows the function is called in the parent. Its usefulness on
368
Windows is thus questionable. In many cases executing the child setup
369
function in the parent can have ill effects, and you should be very
370
careful when porting software to Windows that uses child setup
373
<div class="variablelist"><table border="0">
374
<col align="left" valign="top">
376
<td><span class="term"><em class="parameter"><code>user_data</code></em> :</span></td>
377
<td>user data to pass to the function.
385
<div class="refsect2" lang="en">
386
<a name="id2947317"></a><h3>
387
<a name="g-spawn-async-with-pipes"></a>g_spawn_async_with_pipes ()</h3>
388
<a class="indexterm" name="id2947330"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a> g_spawn_async_with_pipes (const <a href="glib-Basic-Types.html#gchar">gchar</a> *working_directory,
389
<a href="glib-Basic-Types.html#gchar">gchar</a> **argv,
390
<a href="glib-Basic-Types.html#gchar">gchar</a> **envp,
391
<a href="glib-Spawning-Processes.html#GSpawnFlags">GSpawnFlags</a> flags,
392
<a href="glib-Spawning-Processes.html#GSpawnChildSetupFunc">GSpawnChildSetupFunc</a> child_setup,
393
<a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data,
394
<a href="glib-The-Main-Event-Loop.html#GPid">GPid</a> *child_pid,
395
<a href="glib-Basic-Types.html#gint">gint</a> *standard_input,
396
<a href="glib-Basic-Types.html#gint">gint</a> *standard_output,
397
<a href="glib-Basic-Types.html#gint">gint</a> *standard_error,
398
<a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre>
400
Executes a child program asynchronously (your program will not
401
block waiting for the child to exit). The child program is
402
specified by the only argument that must be provided, <em class="parameter"><code>argv</code></em>. <em class="parameter"><code>argv</code></em>
403
should be a <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>-terminated array of strings, to be passed as the
404
argument vector for the child. The first string in <em class="parameter"><code>argv</code></em> is of
405
course the name of the program to execute. By default, the name of
406
the program must be a full path; the <code class="envar">PATH</code> shell variable
407
will only be searched if you pass the <a href="glib-Spawning-Processes.html#G-SPAWN-SEARCH-PATH:CAPS"><code class="literal">G_SPAWN_SEARCH_PATH</code></a> flag.
410
On Windows, note that all the string or string vector arguments to
411
this function and the other g_spawn*() functions are in UTF-8, the
412
GLib file name encoding. Unicode characters that are not part of
413
the system codepage passed in argument vectors will be correctly
414
available in the spawned program only if it uses wide character API
415
to retrieve its command line. For C programs built with Microsoft's
416
tools it is enough to make the program have a <code class="function">wmain()</code> instead of
417
<code class="function">main()</code>. <code class="function">wmain()</code> has a wide character argument vector as parameter.
420
At least currently, mingw doesn't support <code class="function">wmain()</code>, so if you use
421
mingw to develop the spawned program, it will have to call the
422
undocumented function <code class="function">__wgetmainargs()</code> to get the wide character
423
argument vector and environment. See gspawn-win32-helper.c in the
424
GLib sources or init.c in the mingw runtime sources for a prototype
425
for that function. Alternatively, you can retrieve the Win32 system
426
level wide character command line passed to the spawned program
427
using the <code class="function">GetCommandLineW()</code> function.
430
On Windows the low-level child process creation API
431
<code class="function"><code class="function">CreateProcess()</code></code> doesn't use argument vectors,
432
but a command line. The C runtime library's
433
<code class="function">spawn*()</code> family of functions (which
434
<a href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a> eventually calls) paste the argument
435
vector elements together into a command line, and the C runtime startup code
436
does a corresponding reconstruction of an argument vector from the
437
command line, to be passed to <code class="function">main()</code>. Complications arise when you have
438
argument vector elements that contain spaces of double quotes. The
439
<code class="function">spawn*()</code> functions don't do any quoting or
440
escaping, but on the other hand the startup code does do unquoting
441
and unescaping in order to enable receiving arguments with embedded
442
spaces or double quotes. To work around this asymmetry,
443
<a href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a> will do quoting and escaping on argument
444
vector elements that need it before calling the C runtime
445
<code class="function">spawn()</code> function.
448
<em class="parameter"><code>envp</code></em> is a <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>-terminated array of strings, where each string
449
has the form <code class="literal">KEY=VALUE</code>. This will become
450
the child's environment. If <em class="parameter"><code>envp</code></em> is <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>, the child inherits its
451
parent's environment.
454
<em class="parameter"><code>flags</code></em> should be the bitwise OR of any flags you want to affect the
455
function's behaviour. The <a href="glib-Spawning-Processes.html#G-SPAWN-DO-NOT-REAP-CHILD:CAPS"><code class="literal">G_SPAWN_DO_NOT_REAP_CHILD</code></a> means that
456
the child will not automatically be reaped; you must use a
457
<span class="type">GChildWatch</span> source to be notified about the death of the child
458
process. Eventually you must call <a href="glib-Spawning-Processes.html#g-spawn-close-pid"><code class="function">g_spawn_close_pid()</code></a> on the
459
<em class="parameter"><code>child_pid</code></em>, in order to free resources which may be associated
460
with the child process. (On Unix, using a <span class="type">GChildWatch</span> source is
461
equivalent to calling <code class="function">waitpid()</code> or handling the <code class="literal">SIGCHLD</code> signal
462
manually. On Windows, calling <a href="glib-Spawning-Processes.html#g-spawn-close-pid"><code class="function">g_spawn_close_pid()</code></a> is equivalent
463
to calling <code class="function">CloseHandle()</code> on the process handle returned in
464
<em class="parameter"><code>child_pid</code></em>).
467
<a href="glib-Spawning-Processes.html#G-SPAWN-LEAVE-DESCRIPTORS-OPEN:CAPS"><code class="literal">G_SPAWN_LEAVE_DESCRIPTORS_OPEN</code></a> means that the parent's open file
468
descriptors will be inherited by the child; otherwise all
469
descriptors except stdin/stdout/stderr will be closed before
470
calling <code class="function">exec()</code> in the child. <a href="glib-Spawning-Processes.html#G-SPAWN-SEARCH-PATH:CAPS"><code class="literal">G_SPAWN_SEARCH_PATH</code></a>
471
means that <code class="literal">argv[0]</code> need not be an absolute path, it
472
will be looked for in the user's <code class="envar">PATH</code>.
473
<a href="glib-Spawning-Processes.html#G-SPAWN-STDOUT-TO-DEV-NULL:CAPS"><code class="literal">G_SPAWN_STDOUT_TO_DEV_NULL</code></a> means that the child's standard output will
474
be discarded, instead of going to the same location as the parent's
475
standard output. If you use this flag, <em class="parameter"><code>standard_output</code></em> must be <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.
476
<a href="glib-Spawning-Processes.html#G-SPAWN-STDERR-TO-DEV-NULL:CAPS"><code class="literal">G_SPAWN_STDERR_TO_DEV_NULL</code></a> means that the child's standard error
477
will be discarded, instead of going to the same location as the parent's
478
standard error. If you use this flag, <em class="parameter"><code>standard_error</code></em> must be <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.
479
<a href="glib-Spawning-Processes.html#G-SPAWN-CHILD-INHERITS-STDIN:CAPS"><code class="literal">G_SPAWN_CHILD_INHERITS_STDIN</code></a> means that the child will inherit the parent's
480
standard input (by default, the child's standard input is attached to
481
/dev/null). If you use this flag, <em class="parameter"><code>standard_input</code></em> must be <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.
482
<a href="glib-Spawning-Processes.html#G-SPAWN-FILE-AND-ARGV-ZERO:CAPS"><code class="literal">G_SPAWN_FILE_AND_ARGV_ZERO</code></a> means that the first element of <em class="parameter"><code>argv</code></em> is
483
the file to execute, while the remaining elements are the
484
actual argument vector to pass to the file. Normally
485
<a href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a> uses <em class="parameter"><code>argv</code></em>[0] as the file to execute, and
486
passes all of <em class="parameter"><code>argv</code></em> to the child.
489
<em class="parameter"><code>child_setup</code></em> and <em class="parameter"><code>user_data</code></em> are a function and user data. On POSIX
490
platforms, the function is called in the child after GLib has
491
performed all the setup it plans to perform (including creating
492
pipes, closing file descriptors, etc.) but before calling
493
<code class="function">exec()</code>. That is, <em class="parameter"><code>child_setup</code></em> is called just
494
before calling <code class="function">exec()</code> in the child. Obviously
495
actions taken in this function will only affect the child, not the
496
parent. On Windows, there is no separate <code class="function">fork()</code> and <code class="function">exec()</code>
497
functionality. Child processes are created and run with
498
a single API call, <code class="function">CreateProcess()</code>. <em class="parameter"><code>child_setup</code></em> is
499
called in the parent process just before creating the child
500
process. You should carefully consider what you do in <em class="parameter"><code>child_setup</code></em>
501
if you intend your software to be portable to Windows.
504
If non-<a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>, <em class="parameter"><code>child_pid</code></em> will on Unix be filled with the child's
505
process ID. You can use the process ID to send signals to the
506
child, or to <code class="function">waitpid()</code> if you specified the
507
<a href="glib-Spawning-Processes.html#G-SPAWN-DO-NOT-REAP-CHILD:CAPS"><code class="literal">G_SPAWN_DO_NOT_REAP_CHILD</code></a> flag. On Windows, <em class="parameter"><code>child_pid</code></em> will be
508
filled with a handle to the child process only if you specified the
509
<a href="glib-Spawning-Processes.html#G-SPAWN-DO-NOT-REAP-CHILD:CAPS"><code class="literal">G_SPAWN_DO_NOT_REAP_CHILD</code></a> flag. You can then access the child
510
process using the Win32 API, for example wait for its termination
511
with the <code class="function">WaitFor*()</code> functions, or examine its
512
exit code with <code class="function">GetExitCodeProcess()</code>. You should close the handle
513
with <code class="function">CloseHandle()</code> or <a href="glib-Spawning-Processes.html#g-spawn-close-pid"><code class="function">g_spawn_close_pid()</code></a> when you no longer need it.
516
If non-<a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>, the <em class="parameter"><code>standard_input</code></em>, <em class="parameter"><code>standard_output</code></em>, <em class="parameter"><code>standard_error</code></em>
517
locations will be filled with file descriptors for writing to the child's
518
standard input or reading from its standard output or standard error.
519
The caller of <a href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a> must close these file descriptors
520
when they are no longer in use. If these parameters are <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>, the corresponding
521
pipe won't be created.
524
If <em class="parameter"><code>standard_input</code></em> is NULL, the child's standard input is attached to /dev/null
525
unless <a href="glib-Spawning-Processes.html#G-SPAWN-CHILD-INHERITS-STDIN:CAPS"><code class="literal">G_SPAWN_CHILD_INHERITS_STDIN</code></a> is set.
528
If <em class="parameter"><code>standard_error</code></em> is NULL, the child's standard error goes to the same location
529
as the parent's standard error unless <a href="glib-Spawning-Processes.html#G-SPAWN-STDERR-TO-DEV-NULL:CAPS"><code class="literal">G_SPAWN_STDERR_TO_DEV_NULL</code></a> is set.
532
If <em class="parameter"><code>standard_output</code></em> is NULL, the child's standard output goes to the same location
533
as the parent's standard output unless <a href="glib-Spawning-Processes.html#G-SPAWN-STDOUT-TO-DEV-NULL:CAPS"><code class="literal">G_SPAWN_STDOUT_TO_DEV_NULL</code></a> is set.
536
<em class="parameter"><code>error</code></em> can be <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore errors, or non-<a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to report errors.
537
If an error is set, the function returns <a href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a>. Errors
538
are reported even if they occur in the child (for example if the
539
executable in <code class="literal">argv[0]</code> is not found). Typically
540
the <code class="literal">message</code> field of returned errors should be displayed
541
to users. Possible errors are those from the <a href="glib-Spawning-Processes.html#G-SPAWN-ERROR:CAPS"><span class="type">G_SPAWN_ERROR</span></a> domain.
544
If an error occurs, <em class="parameter"><code>child_pid</code></em>, <em class="parameter"><code>standard_input</code></em>, <em class="parameter"><code>standard_output</code></em>,
545
and <em class="parameter"><code>standard_error</code></em> will not be filled with valid values.
548
If <em class="parameter"><code>child_pid</code></em> is not <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> and an error does not occur then the returned
549
pid must be closed using <a href="glib-Spawning-Processes.html#g-spawn-close-pid"><code class="function">g_spawn_close_pid()</code></a>.</p>
553
<div class="variablelist"><table border="0">
554
<col align="left" valign="top">
557
<td><span class="term"><em class="parameter"><code>working_directory</code></em> :</span></td>
558
<td> child's current working directory, or <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to inherit parent's, in the GLib file name encoding
562
<td><span class="term"><em class="parameter"><code>argv</code></em> :</span></td>
563
<td> child's argument vector, in the GLib file name encoding
567
<td><span class="term"><em class="parameter"><code>envp</code></em> :</span></td>
568
<td> child's environment, or <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to inherit parent's, in the GLib file name encoding
572
<td><span class="term"><em class="parameter"><code>flags</code></em> :</span></td>
573
<td> flags from <a href="glib-Spawning-Processes.html#GSpawnFlags"><span class="type">GSpawnFlags</span></a>
577
<td><span class="term"><em class="parameter"><code>child_setup</code></em> :</span></td>
578
<td> function to run in the child just before <code class="function">exec()</code>
582
<td><span class="term"><em class="parameter"><code>user_data</code></em> :</span></td>
583
<td> user data for <em class="parameter"><code>child_setup</code></em>
587
<td><span class="term"><em class="parameter"><code>child_pid</code></em> :</span></td>
588
<td> return location for child process ID, or <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>
592
<td><span class="term"><em class="parameter"><code>standard_input</code></em> :</span></td>
593
<td> return location for file descriptor to write to child's stdin, or <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>
597
<td><span class="term"><em class="parameter"><code>standard_output</code></em> :</span></td>
598
<td> return location for file descriptor to read child's stdout, or <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>
602
<td><span class="term"><em class="parameter"><code>standard_error</code></em> :</span></td>
603
<td> return location for file descriptor to read child's stderr, or <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>
607
<td><span class="term"><em class="parameter"><code>error</code></em> :</span></td>
608
<td> return location for error
612
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
613
<td> <a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> on success, <a href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if an error was set
620
<div class="refsect2" lang="en">
621
<a name="id2948738"></a><h3>
622
<a name="g-spawn-async"></a>g_spawn_async ()</h3>
623
<a class="indexterm" name="id2948751"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a> g_spawn_async (const <a href="glib-Basic-Types.html#gchar">gchar</a> *working_directory,
624
<a href="glib-Basic-Types.html#gchar">gchar</a> **argv,
625
<a href="glib-Basic-Types.html#gchar">gchar</a> **envp,
626
<a href="glib-Spawning-Processes.html#GSpawnFlags">GSpawnFlags</a> flags,
627
<a href="glib-Spawning-Processes.html#GSpawnChildSetupFunc">GSpawnChildSetupFunc</a> child_setup,
628
<a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data,
629
<a href="glib-The-Main-Event-Loop.html#GPid">GPid</a> *child_pid,
630
<a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre>
632
See <a href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a> for a full description; this function
633
simply calls the <a href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a> without any pipes.</p>
637
<div class="variablelist"><table border="0">
638
<col align="left" valign="top">
641
<td><span class="term"><em class="parameter"><code>working_directory</code></em> :</span></td>
642
<td> child's current working directory, or <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to inherit parent's
646
<td><span class="term"><em class="parameter"><code>argv</code></em> :</span></td>
647
<td> child's argument vector
651
<td><span class="term"><em class="parameter"><code>envp</code></em> :</span></td>
652
<td> child's environment, or <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to inherit parent's
656
<td><span class="term"><em class="parameter"><code>flags</code></em> :</span></td>
657
<td> flags from <a href="glib-Spawning-Processes.html#GSpawnFlags"><span class="type">GSpawnFlags</span></a>
661
<td><span class="term"><em class="parameter"><code>child_setup</code></em> :</span></td>
662
<td> function to run in the child just before <code class="function">exec()</code>
666
<td><span class="term"><em class="parameter"><code>user_data</code></em> :</span></td>
667
<td> user data for <em class="parameter"><code>child_setup</code></em>
671
<td><span class="term"><em class="parameter"><code>child_pid</code></em> :</span></td>
672
<td> return location for child process ID, or <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>
676
<td><span class="term"><em class="parameter"><code>error</code></em> :</span></td>
677
<td> return location for error
681
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
682
<td> <a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> on success, <a href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if error is set
689
<div class="refsect2" lang="en">
690
<a name="id2949065"></a><h3>
691
<a name="g-spawn-sync"></a>g_spawn_sync ()</h3>
692
<a class="indexterm" name="id2949078"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a> g_spawn_sync (const <a href="glib-Basic-Types.html#gchar">gchar</a> *working_directory,
693
<a href="glib-Basic-Types.html#gchar">gchar</a> **argv,
694
<a href="glib-Basic-Types.html#gchar">gchar</a> **envp,
695
<a href="glib-Spawning-Processes.html#GSpawnFlags">GSpawnFlags</a> flags,
696
<a href="glib-Spawning-Processes.html#GSpawnChildSetupFunc">GSpawnChildSetupFunc</a> child_setup,
697
<a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data,
698
<a href="glib-Basic-Types.html#gchar">gchar</a> **standard_output,
699
<a href="glib-Basic-Types.html#gchar">gchar</a> **standard_error,
700
<a href="glib-Basic-Types.html#gint">gint</a> *exit_status,
701
<a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre>
703
Executes a child synchronously (waits for the child to exit before returning).
704
All output from the child is stored in <em class="parameter"><code>standard_output</code></em> and <em class="parameter"><code>standard_error</code></em>,
705
if those parameters are non-<a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. If <em class="parameter"><code>exit_status</code></em> is non-<a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>, the exit
706
status of the child is stored there as it would be returned by
707
<code class="function">waitpid()</code>; standard UNIX macros such as <code class="function">WIFEXITED()</code> and <code class="function">WEXITSTATUS()</code>
708
must be used to evaluate the exit status. If an error occurs, no data is
709
returned in <em class="parameter"><code>standard_output</code></em>, <em class="parameter"><code>standard_error</code></em>, or <em class="parameter"><code>exit_status</code></em>.
712
This function calls <a href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a> internally; see that
713
function for full details on the other parameters and details on
714
how these functions work on Windows.</p>
718
<div class="variablelist"><table border="0">
719
<col align="left" valign="top">
722
<td><span class="term"><em class="parameter"><code>working_directory</code></em> :</span></td>
723
<td> child's current working directory, or <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to inherit parent's
727
<td><span class="term"><em class="parameter"><code>argv</code></em> :</span></td>
728
<td> child's argument vector
732
<td><span class="term"><em class="parameter"><code>envp</code></em> :</span></td>
733
<td> child's environment, or <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to inherit parent's
737
<td><span class="term"><em class="parameter"><code>flags</code></em> :</span></td>
738
<td> flags from <a href="glib-Spawning-Processes.html#GSpawnFlags"><span class="type">GSpawnFlags</span></a>
742
<td><span class="term"><em class="parameter"><code>child_setup</code></em> :</span></td>
743
<td> function to run in the child just before <code class="function">exec()</code>
747
<td><span class="term"><em class="parameter"><code>user_data</code></em> :</span></td>
748
<td> user data for <em class="parameter"><code>child_setup</code></em>
752
<td><span class="term"><em class="parameter"><code>standard_output</code></em> :</span></td>
753
<td> return location for child output
757
<td><span class="term"><em class="parameter"><code>standard_error</code></em> :</span></td>
758
<td> return location for child error messages
762
<td><span class="term"><em class="parameter"><code>exit_status</code></em> :</span></td>
763
<td> return location for child exit status, as returned by <code class="function">waitpid()</code>
767
<td><span class="term"><em class="parameter"><code>error</code></em> :</span></td>
768
<td> return location for error
772
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
773
<td> <a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> on success, <a href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if an error was set.
780
<div class="refsect2" lang="en">
781
<a name="id2949526"></a><h3>
782
<a name="g-spawn-command-line-async"></a>g_spawn_command_line_async ()</h3>
783
<a class="indexterm" name="id2949540"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a> g_spawn_command_line_async (const <a href="glib-Basic-Types.html#gchar">gchar</a> *command_line,
784
<a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre>
786
A simple version of <a href="glib-Spawning-Processes.html#g-spawn-async"><code class="function">g_spawn_async()</code></a> that parses a command line with
787
<a href="glib-Shell-related-Utilities.html#g-shell-parse-argv"><code class="function">g_shell_parse_argv()</code></a> and passes it to <a href="glib-Spawning-Processes.html#g-spawn-async"><code class="function">g_spawn_async()</code></a>. Runs a
788
command line in the background. Unlike <a href="glib-Spawning-Processes.html#g-spawn-async"><code class="function">g_spawn_async()</code></a>, the
789
<a href="glib-Spawning-Processes.html#G-SPAWN-SEARCH-PATH:CAPS"><code class="literal">G_SPAWN_SEARCH_PATH</code></a> flag is enabled, other flags are not. Note
790
that <a href="glib-Spawning-Processes.html#G-SPAWN-SEARCH-PATH:CAPS"><code class="literal">G_SPAWN_SEARCH_PATH</code></a> can have security implications, so
791
consider using <a href="glib-Spawning-Processes.html#g-spawn-async"><code class="function">g_spawn_async()</code></a> directly if appropriate. Possible
792
errors are those from <a href="glib-Shell-related-Utilities.html#g-shell-parse-argv"><code class="function">g_shell_parse_argv()</code></a> and <a href="glib-Spawning-Processes.html#g-spawn-async"><code class="function">g_spawn_async()</code></a>.
795
The same concerns on Windows apply as for <a href="glib-Spawning-Processes.html#g-spawn-command-line-sync"><code class="function">g_spawn_command_line_sync()</code></a>.</p>
799
<div class="variablelist"><table border="0">
800
<col align="left" valign="top">
803
<td><span class="term"><em class="parameter"><code>command_line</code></em> :</span></td>
808
<td><span class="term"><em class="parameter"><code>error</code></em> :</span></td>
809
<td> return location for errors
813
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
814
<td> <a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> on success, <a href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if error is set.
821
<div class="refsect2" lang="en">
822
<a name="id2949760"></a><h3>
823
<a name="g-spawn-command-line-sync"></a>g_spawn_command_line_sync ()</h3>
824
<a class="indexterm" name="id2949774"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a> g_spawn_command_line_sync (const <a href="glib-Basic-Types.html#gchar">gchar</a> *command_line,
825
<a href="glib-Basic-Types.html#gchar">gchar</a> **standard_output,
826
<a href="glib-Basic-Types.html#gchar">gchar</a> **standard_error,
827
<a href="glib-Basic-Types.html#gint">gint</a> *exit_status,
828
<a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre>
830
A simple version of <a href="glib-Spawning-Processes.html#g-spawn-sync"><code class="function">g_spawn_sync()</code></a> with little-used parameters
831
removed, taking a command line instead of an argument vector. See
832
<a href="glib-Spawning-Processes.html#g-spawn-sync"><code class="function">g_spawn_sync()</code></a> for full details. <em class="parameter"><code>command_line</code></em> will be parsed by
833
<a href="glib-Shell-related-Utilities.html#g-shell-parse-argv"><code class="function">g_shell_parse_argv()</code></a>. Unlike <a href="glib-Spawning-Processes.html#g-spawn-sync"><code class="function">g_spawn_sync()</code></a>, the <a href="glib-Spawning-Processes.html#G-SPAWN-SEARCH-PATH:CAPS"><code class="literal">G_SPAWN_SEARCH_PATH</code></a> flag
834
is enabled. Note that <a href="glib-Spawning-Processes.html#G-SPAWN-SEARCH-PATH:CAPS"><code class="literal">G_SPAWN_SEARCH_PATH</code></a> can have security
835
implications, so consider using <a href="glib-Spawning-Processes.html#g-spawn-sync"><code class="function">g_spawn_sync()</code></a> directly if
836
appropriate. Possible errors are those from <a href="glib-Spawning-Processes.html#g-spawn-sync"><code class="function">g_spawn_sync()</code></a> and those
837
from <a href="glib-Shell-related-Utilities.html#g-shell-parse-argv"><code class="function">g_shell_parse_argv()</code></a>.
840
If <em class="parameter"><code>exit_status</code></em> is non-<a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>, the exit status of the child is stored there as
841
it would be returned by <code class="function">waitpid()</code>; standard UNIX macros such as <code class="function">WIFEXITED()</code>
842
and <code class="function">WEXITSTATUS()</code> must be used to evaluate the exit status.
845
On Windows, please note the implications of <a href="glib-Shell-related-Utilities.html#g-shell-parse-argv"><code class="function">g_shell_parse_argv()</code></a>
846
parsing <em class="parameter"><code>command_line</code></em>. Parsing is done according to Unix shell rules, not
847
Windows command interpreter rules.
848
Space is a separator, and backslashes are
849
special. Thus you cannot simply pass a <em class="parameter"><code>command_line</code></em> containing
850
canonical Windows paths, like "c:\\program files\\app\\app.exe", as
851
the backslashes will be eaten, and the space will act as a
852
separator. You need to enclose such paths with single quotes, like
853
"'c:\\program files\\app\\app.exe' 'e:\\folder\\argument.txt'".</p>
857
<div class="variablelist"><table border="0">
858
<col align="left" valign="top">
861
<td><span class="term"><em class="parameter"><code>command_line</code></em> :</span></td>
866
<td><span class="term"><em class="parameter"><code>standard_output</code></em> :</span></td>
867
<td> return location for child output
871
<td><span class="term"><em class="parameter"><code>standard_error</code></em> :</span></td>
872
<td> return location for child errors
876
<td><span class="term"><em class="parameter"><code>exit_status</code></em> :</span></td>
877
<td> return location for child exit status, as returned by <code class="function">waitpid()</code>
881
<td><span class="term"><em class="parameter"><code>error</code></em> :</span></td>
882
<td> return location for errors
886
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td>
887
<td> <a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> on success, <a href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if an error was set
894
<div class="refsect2" lang="en">
895
<a name="id2950148"></a><h3>
896
<a name="g-spawn-close-pid"></a>g_spawn_close_pid ()</h3>
897
<a class="indexterm" name="id2950162"></a><pre class="programlisting">void g_spawn_close_pid (<a href="glib-The-Main-Event-Loop.html#GPid">GPid</a> pid);</pre>
899
On some platforms, notably WIN32, the <a href="glib-The-Main-Event-Loop.html#GPid"><span class="type">GPid</span></a> type represents a resource
900
which must be closed to prevent resource leaking. <a href="glib-Spawning-Processes.html#g-spawn-close-pid"><code class="function">g_spawn_close_pid()</code></a>
901
is provided for this purpose. It should be used on all platforms, even
902
though it doesn't do anything under UNIX.</p>
906
<div class="variablelist"><table border="0">
907
<col align="left" valign="top">
909
<td><span class="term"><em class="parameter"><code>pid</code></em> :</span></td>
910
<td> The process identifier to close