~ubuntu-branches/ubuntu/utopic/glib2.0/utopic

« back to all changes in this revision

Viewing changes to docs/reference/glib/html/glib-Spawning-Processes.html

Tags: upstream-2.12.12
ImportĀ upstreamĀ versionĀ 2.12.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
2
<html>
 
3
<head>
 
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">
 
27
</head>
 
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">
 
30
<tr valign="middle">
 
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>
 
36
</tr>
 
37
<tr><td colspan="5" class="shortcuts"><nobr><a href="#id2945417" class="shortcut">Top</a>
 
38
                  &#160;|&#160;
 
39
                  <a href="#id2945892" class="shortcut">Description</a></nobr></td></tr>
 
40
</table>
 
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>
 
44
<td valign="top">
 
45
<h2>
 
46
<a name="id2945417"></a><span class="refentrytitle">Spawning Processes</span>
 
47
</h2>
 
48
<p>Spawning Processes &#8212; process launching with <code class="function"><code class="function">fork()</code></code>/<code class="function"><code class="function">exec()</code></code>.</p>
 
49
</td>
 
50
<td valign="top" align="right"></td>
 
51
</tr></table></div>
 
52
<div class="refsynopsisdiv">
 
53
<h2>Synopsis</h2>
 
54
<pre class="synopsis">
 
55
 
 
56
#include &lt;glib.h&gt;
 
57
 
 
58
 
 
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);
 
100
 
 
101
</pre>
 
102
</div>
 
103
<div class="refsect1" lang="en">
 
104
<a name="id2945892"></a><h2>Description</h2>
 
105
<p>
 
106
 
 
107
</p>
 
108
</div>
 
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
 
115
{
 
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-&gt;message
 
136
                              * should explain
 
137
                              */
 
138
} GSpawnError;
 
139
</pre>
 
140
<p>
 
141
Error codes returned by spawning processes.
 
142
</p>
 
143
<div class="variablelist"><table border="0">
 
144
<col align="left" valign="top">
 
145
<tbody>
 
146
<tr>
 
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.
 
149
</td>
 
150
</tr>
 
151
<tr>
 
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.
 
154
</td>
 
155
</tr>
 
156
<tr>
 
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.
 
159
</td>
 
160
</tr>
 
161
<tr>
 
162
<td><span class="term"><a name="G-SPAWN-ERROR-ACCES:CAPS"></a><code class="literal">G_SPAWN_ERROR_ACCES</code></span></td>
 
163
<td>
 
164
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">EACCES</code>.
 
165
</td>
 
166
</tr>
 
167
<tr>
 
168
<td><span class="term"><a name="G-SPAWN-ERROR-PERM:CAPS"></a><code class="literal">G_SPAWN_ERROR_PERM</code></span></td>
 
169
<td>
 
170
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">EPERM</code>.
 
171
</td>
 
172
</tr>
 
173
<tr>
 
174
<td><span class="term"><a name="G-SPAWN-ERROR-2BIG:CAPS"></a><code class="literal">G_SPAWN_ERROR_2BIG</code></span></td>
 
175
<td>
 
176
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">E2BIG</code>.
 
177
</td>
 
178
</tr>
 
179
<tr>
 
180
<td><span class="term"><a name="G-SPAWN-ERROR-NOEXEC:CAPS"></a><code class="literal">G_SPAWN_ERROR_NOEXEC</code></span></td>
 
181
<td>
 
182
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ENOEXEC</code>.
 
183
</td>
 
184
</tr>
 
185
<tr>
 
186
<td><span class="term"><a name="G-SPAWN-ERROR-NAMETOOLONG:CAPS"></a><code class="literal">G_SPAWN_ERROR_NAMETOOLONG</code></span></td>
 
187
<td>
 
188
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ENAMETOOLONG</code>.
 
189
</td>
 
190
</tr>
 
191
<tr>
 
192
<td><span class="term"><a name="G-SPAWN-ERROR-NOENT:CAPS"></a><code class="literal">G_SPAWN_ERROR_NOENT</code></span></td>
 
193
<td>
 
194
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ENOENT</code>.
 
195
</td>
 
196
</tr>
 
197
<tr>
 
198
<td><span class="term"><a name="G-SPAWN-ERROR-NOMEM:CAPS"></a><code class="literal">G_SPAWN_ERROR_NOMEM</code></span></td>
 
199
<td>
 
200
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ENOMEM</code>.
 
201
</td>
 
202
</tr>
 
203
<tr>
 
204
<td><span class="term"><a name="G-SPAWN-ERROR-NOTDIR:CAPS"></a><code class="literal">G_SPAWN_ERROR_NOTDIR</code></span></td>
 
205
<td>
 
206
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ENOTDIR</code>.
 
207
</td>
 
208
</tr>
 
209
<tr>
 
210
<td><span class="term"><a name="G-SPAWN-ERROR-LOOP:CAPS"></a><code class="literal">G_SPAWN_ERROR_LOOP</code></span></td>
 
211
<td>
 
212
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ELOOP</code>.
 
213
</td>
 
214
</tr>
 
215
<tr>
 
216
<td><span class="term"><a name="G-SPAWN-ERROR-TXTBUSY:CAPS"></a><code class="literal">G_SPAWN_ERROR_TXTBUSY</code></span></td>
 
217
<td>
 
218
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ETXTBUSY</code>.
 
219
</td>
 
220
</tr>
 
221
<tr>
 
222
<td><span class="term"><a name="G-SPAWN-ERROR-IO:CAPS"></a><code class="literal">G_SPAWN_ERROR_IO</code></span></td>
 
223
<td>
 
224
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">EIO</code>.
 
225
</td>
 
226
</tr>
 
227
<tr>
 
228
<td><span class="term"><a name="G-SPAWN-ERROR-NFILE:CAPS"></a><code class="literal">G_SPAWN_ERROR_NFILE</code></span></td>
 
229
<td>
 
230
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ENFILE</code>.
 
231
</td>
 
232
</tr>
 
233
<tr>
 
234
<td><span class="term"><a name="G-SPAWN-ERROR-MFILE:CAPS"></a><code class="literal">G_SPAWN_ERROR_MFILE</code></span></td>
 
235
<td>
 
236
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">EMFILE</code>.
 
237
</td>
 
238
</tr>
 
239
<tr>
 
240
<td><span class="term"><a name="G-SPAWN-ERROR-INVAL:CAPS"></a><code class="literal">G_SPAWN_ERROR_INVAL</code></span></td>
 
241
<td>
 
242
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">EINVAL</code>.
 
243
</td>
 
244
</tr>
 
245
<tr>
 
246
<td><span class="term"><a name="G-SPAWN-ERROR-ISDIR:CAPS"></a><code class="literal">G_SPAWN_ERROR_ISDIR</code></span></td>
 
247
<td>
 
248
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">EISDIR</code>.
 
249
</td>
 
250
</tr>
 
251
<tr>
 
252
<td><span class="term"><a name="G-SPAWN-ERROR-LIBBAD:CAPS"></a><code class="literal">G_SPAWN_ERROR_LIBBAD</code></span></td>
 
253
<td>
 
254
<code class="function"><code class="function">execv()</code></code> returned <code class="literal">ELIBBAD</code>.
 
255
</td>
 
256
</tr>
 
257
<tr>
 
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-&gt;message</code> should explain.
 
260
 
 
261
</td>
 
262
</tr>
 
263
</tbody>
 
264
</table></div>
 
265
</div>
 
266
<hr>
 
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 ()
 
271
</pre>
 
272
<p>
 
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
 
275
error domains.
 
276
</p>
 
277
</div>
 
278
<hr>
 
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
 
283
{
 
284
  G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1 &lt;&lt; 0,
 
285
  G_SPAWN_DO_NOT_REAP_CHILD      = 1 &lt;&lt; 1,
 
286
  /* look for argv[0] in the path i.e. use execvp() */
 
287
  G_SPAWN_SEARCH_PATH            = 1 &lt;&lt; 2,
 
288
  /* Dump output to /dev/null */
 
289
  G_SPAWN_STDOUT_TO_DEV_NULL     = 1 &lt;&lt; 3,
 
290
  G_SPAWN_STDERR_TO_DEV_NULL     = 1 &lt;&lt; 4,
 
291
  G_SPAWN_CHILD_INHERITS_STDIN   = 1 &lt;&lt; 5,
 
292
  G_SPAWN_FILE_AND_ARGV_ZERO     = 1 &lt;&lt; 6
 
293
} GSpawnFlags;
 
294
</pre>
 
295
<p>
 
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>.
 
297
</p>
 
298
<div class="variablelist"><table border="0">
 
299
<col align="left" valign="top">
 
300
<tbody>
 
301
<tr>
 
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.
 
306
</td>
 
307
</tr>
 
308
<tr>
 
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.
 
313
</td>
 
314
</tr>
 
315
<tr>
 
316
<td><span class="term"><a name="G-SPAWN-SEARCH-PATH:CAPS"></a><code class="literal">G_SPAWN_SEARCH_PATH</code></span></td>
 
317
<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>.
 
320
</td>
 
321
</tr>
 
322
<tr>
 
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.
 
326
</td>
 
327
</tr>
 
328
<tr>
 
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.
 
331
</td>
 
332
</tr>
 
333
<tr>
 
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>).
 
338
</td>
 
339
</tr>
 
340
<tr>
 
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.
 
347
 
 
348
</td>
 
349
</tr>
 
350
</tbody>
 
351
</table></div>
 
352
</div>
 
353
<hr>
 
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>
 
358
<p>
 
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
 
364
the parent.
 
365
</p>
 
366
<p>
 
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
 
371
functions.
 
372
</p>
 
373
<div class="variablelist"><table border="0">
 
374
<col align="left" valign="top">
 
375
<tbody><tr>
 
376
<td><span class="term"><em class="parameter"><code>user_data</code></em>&#160;:</span></td>
 
377
<td>user data to pass to the function.
 
378
 
 
379
 
 
380
</td>
 
381
</tr></tbody>
 
382
</table></div>
 
383
</div>
 
384
<hr>
 
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>
 
399
<p>
 
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.
 
408
</p>
 
409
<p>
 
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.
 
418
</p>
 
419
<p>
 
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.
 
428
</p>
 
429
<p>
 
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.
 
446
</p>
 
447
<p>
 
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.
 
452
</p>
 
453
<p>
 
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>).
 
465
</p>
 
466
<p>
 
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.
 
487
</p>
 
488
<p>
 
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.
 
502
</p>
 
503
<p>
 
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.
 
514
</p>
 
515
<p>
 
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.
 
522
</p>
 
523
<p>
 
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.
 
526
</p>
 
527
<p>
 
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.
 
530
</p>
 
531
<p>
 
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.
 
534
</p>
 
535
<p>
 
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.
 
542
</p>
 
543
<p>
 
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.
 
546
</p>
 
547
<p>
 
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>
 
550
<p>
 
551
 
 
552
</p>
 
553
<div class="variablelist"><table border="0">
 
554
<col align="left" valign="top">
 
555
<tbody>
 
556
<tr>
 
557
<td><span class="term"><em class="parameter"><code>working_directory</code></em>&#160;:</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
 
559
</td>
 
560
</tr>
 
561
<tr>
 
562
<td><span class="term"><em class="parameter"><code>argv</code></em>&#160;:</span></td>
 
563
<td> child's argument vector, in the GLib file name encoding
 
564
</td>
 
565
</tr>
 
566
<tr>
 
567
<td><span class="term"><em class="parameter"><code>envp</code></em>&#160;:</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
 
569
</td>
 
570
</tr>
 
571
<tr>
 
572
<td><span class="term"><em class="parameter"><code>flags</code></em>&#160;:</span></td>
 
573
<td> flags from <a href="glib-Spawning-Processes.html#GSpawnFlags"><span class="type">GSpawnFlags</span></a>
 
574
</td>
 
575
</tr>
 
576
<tr>
 
577
<td><span class="term"><em class="parameter"><code>child_setup</code></em>&#160;:</span></td>
 
578
<td> function to run in the child just before <code class="function">exec()</code>
 
579
</td>
 
580
</tr>
 
581
<tr>
 
582
<td><span class="term"><em class="parameter"><code>user_data</code></em>&#160;:</span></td>
 
583
<td> user data for <em class="parameter"><code>child_setup</code></em>
 
584
</td>
 
585
</tr>
 
586
<tr>
 
587
<td><span class="term"><em class="parameter"><code>child_pid</code></em>&#160;:</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>
 
589
</td>
 
590
</tr>
 
591
<tr>
 
592
<td><span class="term"><em class="parameter"><code>standard_input</code></em>&#160;:</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>
 
594
</td>
 
595
</tr>
 
596
<tr>
 
597
<td><span class="term"><em class="parameter"><code>standard_output</code></em>&#160;:</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>
 
599
</td>
 
600
</tr>
 
601
<tr>
 
602
<td><span class="term"><em class="parameter"><code>standard_error</code></em>&#160;:</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>
 
604
</td>
 
605
</tr>
 
606
<tr>
 
607
<td><span class="term"><em class="parameter"><code>error</code></em>&#160;:</span></td>
 
608
<td> return location for error
 
609
</td>
 
610
</tr>
 
611
<tr>
 
612
<td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</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
 
614
</td>
 
615
</tr>
 
616
</tbody>
 
617
</table></div>
 
618
</div>
 
619
<hr>
 
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>
 
631
<p>
 
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>
 
634
<p>
 
635
 
 
636
</p>
 
637
<div class="variablelist"><table border="0">
 
638
<col align="left" valign="top">
 
639
<tbody>
 
640
<tr>
 
641
<td><span class="term"><em class="parameter"><code>working_directory</code></em>&#160;:</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
 
643
</td>
 
644
</tr>
 
645
<tr>
 
646
<td><span class="term"><em class="parameter"><code>argv</code></em>&#160;:</span></td>
 
647
<td> child's argument vector
 
648
</td>
 
649
</tr>
 
650
<tr>
 
651
<td><span class="term"><em class="parameter"><code>envp</code></em>&#160;:</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
 
653
</td>
 
654
</tr>
 
655
<tr>
 
656
<td><span class="term"><em class="parameter"><code>flags</code></em>&#160;:</span></td>
 
657
<td> flags from <a href="glib-Spawning-Processes.html#GSpawnFlags"><span class="type">GSpawnFlags</span></a>
 
658
</td>
 
659
</tr>
 
660
<tr>
 
661
<td><span class="term"><em class="parameter"><code>child_setup</code></em>&#160;:</span></td>
 
662
<td> function to run in the child just before <code class="function">exec()</code>
 
663
</td>
 
664
</tr>
 
665
<tr>
 
666
<td><span class="term"><em class="parameter"><code>user_data</code></em>&#160;:</span></td>
 
667
<td> user data for <em class="parameter"><code>child_setup</code></em>
 
668
</td>
 
669
</tr>
 
670
<tr>
 
671
<td><span class="term"><em class="parameter"><code>child_pid</code></em>&#160;:</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>
 
673
</td>
 
674
</tr>
 
675
<tr>
 
676
<td><span class="term"><em class="parameter"><code>error</code></em>&#160;:</span></td>
 
677
<td> return location for error
 
678
</td>
 
679
</tr>
 
680
<tr>
 
681
<td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</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
 
683
</td>
 
684
</tr>
 
685
</tbody>
 
686
</table></div>
 
687
</div>
 
688
<hr>
 
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>
 
702
<p>
 
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>.
 
710
</p>
 
711
<p>
 
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>
 
715
<p>
 
716
 
 
717
</p>
 
718
<div class="variablelist"><table border="0">
 
719
<col align="left" valign="top">
 
720
<tbody>
 
721
<tr>
 
722
<td><span class="term"><em class="parameter"><code>working_directory</code></em>&#160;:</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
 
724
</td>
 
725
</tr>
 
726
<tr>
 
727
<td><span class="term"><em class="parameter"><code>argv</code></em>&#160;:</span></td>
 
728
<td> child's argument vector
 
729
</td>
 
730
</tr>
 
731
<tr>
 
732
<td><span class="term"><em class="parameter"><code>envp</code></em>&#160;:</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
 
734
</td>
 
735
</tr>
 
736
<tr>
 
737
<td><span class="term"><em class="parameter"><code>flags</code></em>&#160;:</span></td>
 
738
<td> flags from <a href="glib-Spawning-Processes.html#GSpawnFlags"><span class="type">GSpawnFlags</span></a>
 
739
</td>
 
740
</tr>
 
741
<tr>
 
742
<td><span class="term"><em class="parameter"><code>child_setup</code></em>&#160;:</span></td>
 
743
<td> function to run in the child just before <code class="function">exec()</code>
 
744
</td>
 
745
</tr>
 
746
<tr>
 
747
<td><span class="term"><em class="parameter"><code>user_data</code></em>&#160;:</span></td>
 
748
<td> user data for <em class="parameter"><code>child_setup</code></em>
 
749
</td>
 
750
</tr>
 
751
<tr>
 
752
<td><span class="term"><em class="parameter"><code>standard_output</code></em>&#160;:</span></td>
 
753
<td> return location for child output 
 
754
</td>
 
755
</tr>
 
756
<tr>
 
757
<td><span class="term"><em class="parameter"><code>standard_error</code></em>&#160;:</span></td>
 
758
<td> return location for child error messages
 
759
</td>
 
760
</tr>
 
761
<tr>
 
762
<td><span class="term"><em class="parameter"><code>exit_status</code></em>&#160;:</span></td>
 
763
<td> return location for child exit status, as returned by <code class="function">waitpid()</code>
 
764
</td>
 
765
</tr>
 
766
<tr>
 
767
<td><span class="term"><em class="parameter"><code>error</code></em>&#160;:</span></td>
 
768
<td> return location for error
 
769
</td>
 
770
</tr>
 
771
<tr>
 
772
<td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</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.
 
774
</td>
 
775
</tr>
 
776
</tbody>
 
777
</table></div>
 
778
</div>
 
779
<hr>
 
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>
 
785
<p>
 
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>.
 
793
</p>
 
794
<p>
 
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>
 
796
<p>
 
797
 
 
798
</p>
 
799
<div class="variablelist"><table border="0">
 
800
<col align="left" valign="top">
 
801
<tbody>
 
802
<tr>
 
803
<td><span class="term"><em class="parameter"><code>command_line</code></em>&#160;:</span></td>
 
804
<td> a command line
 
805
</td>
 
806
</tr>
 
807
<tr>
 
808
<td><span class="term"><em class="parameter"><code>error</code></em>&#160;:</span></td>
 
809
<td> return location for errors
 
810
</td>
 
811
</tr>
 
812
<tr>
 
813
<td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</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.
 
815
</td>
 
816
</tr>
 
817
</tbody>
 
818
</table></div>
 
819
</div>
 
820
<hr>
 
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>
 
829
<p>
 
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>.
 
838
</p>
 
839
<p>
 
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.
 
843
</p>
 
844
<p>
 
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>
 
854
<p>
 
855
 
 
856
</p>
 
857
<div class="variablelist"><table border="0">
 
858
<col align="left" valign="top">
 
859
<tbody>
 
860
<tr>
 
861
<td><span class="term"><em class="parameter"><code>command_line</code></em>&#160;:</span></td>
 
862
<td> a command line 
 
863
</td>
 
864
</tr>
 
865
<tr>
 
866
<td><span class="term"><em class="parameter"><code>standard_output</code></em>&#160;:</span></td>
 
867
<td> return location for child output
 
868
</td>
 
869
</tr>
 
870
<tr>
 
871
<td><span class="term"><em class="parameter"><code>standard_error</code></em>&#160;:</span></td>
 
872
<td> return location for child errors
 
873
</td>
 
874
</tr>
 
875
<tr>
 
876
<td><span class="term"><em class="parameter"><code>exit_status</code></em>&#160;:</span></td>
 
877
<td> return location for child exit status, as returned by <code class="function">waitpid()</code>
 
878
</td>
 
879
</tr>
 
880
<tr>
 
881
<td><span class="term"><em class="parameter"><code>error</code></em>&#160;:</span></td>
 
882
<td> return location for errors
 
883
</td>
 
884
</tr>
 
885
<tr>
 
886
<td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</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
 
888
</td>
 
889
</tr>
 
890
</tbody>
 
891
</table></div>
 
892
</div>
 
893
<hr>
 
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>
 
898
<p>
 
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>
 
903
<p>
 
904
 
 
905
</p>
 
906
<div class="variablelist"><table border="0">
 
907
<col align="left" valign="top">
 
908
<tbody><tr>
 
909
<td><span class="term"><em class="parameter"><code>pid</code></em>&#160;:</span></td>
 
910
<td> The process identifier to close
 
911
</td>
 
912
</tr></tbody>
 
913
</table></div>
 
914
</div>
 
915
</div>
 
916
</div>
 
917
</body>
 
918
</html>