📄 glib-spawning-processes.html
字号:
Executes a child synchronously (waits for the child to exit before returning).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>,if those parameters are non-<code class="literal">NULL</code>. If <em class="parameter"><code>exit_status</code></em> is non-<code class="literal">NULL</code>, the exit status of the child is stored there as it would be returned by <code class="function">waitpid()</code>; standard UNIX macros such as <code class="function">WIFEXITED()</code> and <code class="function">WEXITSTATUS()</code> must be used to evaluate the exit status. If an error occurs, no data is 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>.</p><p>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 functionfor full details on the other parameters.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>working_directory</code></em> :</span></td><td> child's current working directory, or <code class="literal">NULL</code> to inherit parent's</td></tr><tr><td><span class="term"><em class="parameter"><code>argv</code></em> :</span></td><td> child's argument vector</td></tr><tr><td><span class="term"><em class="parameter"><code>envp</code></em> :</span></td><td> child's environment, or <code class="literal">NULL</code> to inherit parent's</td></tr><tr><td><span class="term"><em class="parameter"><code>flags</code></em> :</span></td><td> flags from <a href="glib-Spawning-Processes.html#GSpawnFlags"><span class="type">GSpawnFlags</span></a></td></tr><tr><td><span class="term"><em class="parameter"><code>child_setup</code></em> :</span></td><td> function to run in the child just before <code class="function">exec()</code></td></tr><tr><td><span class="term"><em class="parameter"><code>user_data</code></em> :</span></td><td> user data for <em class="parameter"><code>child_setup</code></em></td></tr><tr><td><span class="term"><em class="parameter"><code>standard_output</code></em> :</span></td><td> return location for child output </td></tr><tr><td><span class="term"><em class="parameter"><code>standard_error</code></em> :</span></td><td> return location for child error messages</td></tr><tr><td><span class="term"><em class="parameter"><code>exit_status</code></em> :</span></td><td> return location for child exit status, as returned by <code class="function">waitpid()</code></td></tr><tr><td><span class="term"><em class="parameter"><code>error</code></em> :</span></td><td> return location for error</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> <code class="literal">TRUE</code> on success, <code class="literal">FALSE</code> if an error was set.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3046800"></a><h3><a name="g-spawn-command-line-async"></a>g_spawn_command_line_async ()</h3><a class="indexterm" name="id3046812"></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, <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>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<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 acommand line in the background. Unlike <a href="glib-Spawning-Processes.html#g-spawn-async"><code class="function">g_spawn_async()</code></a>, the<code class="literal">G_SPAWN_SEARCH_PATH</code> flag is enabled, other flags are not. Notethat <code class="literal">G_SPAWN_SEARCH_PATH</code> can have security implications, soconsider using <a href="glib-Spawning-Processes.html#g-spawn-async"><code class="function">g_spawn_async()</code></a> directly if appropriate. Possibleerrors 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>.</p><p>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><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>command_line</code></em> :</span></td><td> a command line</td></tr><tr><td><span class="term"><em class="parameter"><code>error</code></em> :</span></td><td> return location for errors</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> <code class="literal">TRUE</code> on success, <code class="literal">FALSE</code> if error is set.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3047012"></a><h3><a name="g-spawn-command-line-sync"></a>g_spawn_command_line_sync ()</h3><a class="indexterm" name="id3047024"></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, <a href="glib-Basic-Types.html#gchar">gchar</a> **standard_output, <a href="glib-Basic-Types.html#gchar">gchar</a> **standard_error, <a href="glib-Basic-Types.html#gint">gint</a> *exit_status, <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>A simple version of <a href="glib-Spawning-Processes.html#g-spawn-sync"><code class="function">g_spawn_sync()</code></a> with little-used parametersremoved, taking a command line instead of an argument vector. See<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<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 <code class="literal">G_SPAWN_SEARCH_PATH</code> flagis enabled. Note that <code class="literal">G_SPAWN_SEARCH_PATH</code> can have securityimplications, so consider using <a href="glib-Spawning-Processes.html#g-spawn-sync"><code class="function">g_spawn_sync()</code></a> directly ifappropriate. Possible errors are those from <a href="glib-Spawning-Processes.html#g-spawn-sync"><code class="function">g_spawn_sync()</code></a> and thosefrom <a href="glib-Shell-related-Utilities.html#g-shell-parse-argv"><code class="function">g_shell_parse_argv()</code></a>.</p><p>If <em class="parameter"><code>exit_status</code></em> is non-<code class="literal">NULL</code>, the exit status of the child is stored there asit would be returned by <code class="function">waitpid()</code>; standard UNIX macros such as <code class="function">WIFEXITED()</code>and <code class="function">WEXITSTATUS()</code> must be used to evaluate the exit status.</p><p>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>parsing <em class="parameter"><code>command_line</code></em>. Space is a separator, and backslashes arespecial. Thus you cannot simply pass a <em class="parameter"><code>command_line</code></em> containingcanonical Windows paths, like "c:\\program files\\app\\app.exe", asthe backslashes will be eaten, and the space will act as aseparator. You need to enclose such paths with single quotes, like"'c:\\program files\\app\\app.exe' 'e:\\folder\\argument.txt'".</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>command_line</code></em> :</span></td><td> a command line </td></tr><tr><td><span class="term"><em class="parameter"><code>standard_output</code></em> :</span></td><td> return location for child output</td></tr><tr><td><span class="term"><em class="parameter"><code>standard_error</code></em> :</span></td><td> return location for child errors</td></tr><tr><td><span class="term"><em class="parameter"><code>exit_status</code></em> :</span></td><td> return location for child exit status, as returned by <code class="function">waitpid()</code></td></tr><tr><td><span class="term"><em class="parameter"><code>error</code></em> :</span></td><td> return location for errors</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> <code class="literal">TRUE</code> on success, <code class="literal">FALSE</code> if an error was set</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3047374"></a><h3><a name="g-spawn-close-pid"></a>g_spawn_close_pid ()</h3><a class="indexterm" name="id3047385"></a><pre class="programlisting">void g_spawn_close_pid (<a href="glib-The-Main-Event-Loop.html#GPid">GPid</a> pid);</pre><p>On some platforms, notably WIN32, the <a href="glib-The-Main-Event-Loop.html#GPid"><span class="type">GPid</span></a> type represents a resourcewhich 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>is provided for this purpose. It should be used on all platforms, eventhough it doesn't do anything under UNIX.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>pid</code></em> :</span></td><td> The process identifier to close</td></tr></tbody></table></div></div></div></div><table class="navigation" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle"><td align="left"><a accesskey="p" href="glib-Timers.html"><b><< Timers</b></a></td><td align="right"><a accesskey="n" href="glib-File-Utilities.html"><b>File Utilities >></b></a></td></tr></table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -