📄 spawn.sgml
字号:
<refsect2><title><anchor id="G-SPAWN-ERROR-CAPS">G_SPAWN_ERROR</title><programlisting>#define G_SPAWN_ERROR g_spawn_error_quark ()</programlisting><para>Error domain for spawning processes. Errors in this domain willbe from the <link linkend="GSpawnError">GSpawnError</link> enumeration. See <link linkend="GError">GError</link> for information onerror domains.</para></refsect2><refsect2><title><anchor id="GSpawnFlags">enum GSpawnFlags</title><programlisting>typedef enum{ G_SPAWN_LEAVE_DESCRIPTORS_OPEN = 1 << 0, G_SPAWN_DO_NOT_REAP_CHILD = 1 << 1, /* look for argv[0] in the path i.e. use execvp() */ G_SPAWN_SEARCH_PATH = 1 << 2, /* Dump output to /dev/null */ G_SPAWN_STDOUT_TO_DEV_NULL = 1 << 3, G_SPAWN_STDERR_TO_DEV_NULL = 1 << 4, G_SPAWN_CHILD_INHERITS_STDIN = 1 << 5, G_SPAWN_FILE_AND_ARGV_ZERO = 1 << 6} GSpawnFlags;</programlisting><para>Flags passed to <link linkend="g-spawn-sync">g_spawn_sync</link>(), <link linkend="g-spawn-async">g_spawn_async</link>() and <link linkend="g-spawn-async-with-pipes">g_spawn_async_with_pipes</link>().</para><informaltable pgwide="1" frame="none" role="enum"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry><literal>G_SPAWN_LEAVE_DESCRIPTORS_OPEN</literal></entry><entry>the parent's open file descriptors will be inherited by the child; otherwise all descriptors except stdin/stdout/stderr will be closed before calling <function><link linkend="exec">exec</link>()</function> in the child.</entry></row><row><entry><literal>G_SPAWN_DO_NOT_REAP_CHILD</literal></entry><entry>the child will not be automatically reaped; you must call <function><link linkend="waitpid">waitpid</link>()</function> or handle <literal>SIGCHLD</literal> yourself, or the child will become a zombie.</entry></row><row><entry><literal>G_SPAWN_SEARCH_PATH</literal></entry><entry><literal>argv[0]</literal> need not be an absolute path, it will be looked for in the user's <envar>PATH</envar>.</entry></row><row><entry><literal>G_SPAWN_STDOUT_TO_DEV_NULL</literal></entry><entry>the child's standad output will be discarded, instead of going to the same location as the parent's standard output.</entry></row><row><entry><literal>G_SPAWN_STDERR_TO_DEV_NULL</literal></entry><entry>the child's standard error will be discarded.</entry></row><row><entry><literal>G_SPAWN_CHILD_INHERITS_STDIN</literal></entry><entry>the child will inherit the parent's standard input (by default, the child's standard input is attached to <filename>/dev/null</filename>).</entry></row><row><entry><literal>G_SPAWN_FILE_AND_ARGV_ZERO</literal></entry><entry>the first element of <literal>argv</literal> is the file to execute, while the remaining elements are the actual argument vector to pass to the file. Normally <link linkend="g-spawn-async-with-pipes">g_spawn_async_with_pipes</link>() uses <literal>argv[0]</literal> as the file to execute, and passes all of <literal>argv</literal> to the child.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="GSpawnChildSetupFunc">GSpawnChildSetupFunc ()</title><programlisting>void (*GSpawnChildSetupFunc) (<link linkend="gpointer">gpointer</link> user_data);</programlisting><para>Specifies the type of the setup function passed to <link linkend="g-spawn-async">g_spawn_async</link>(),<link linkend="g-spawn-sync">g_spawn_sync</link>() and <link linkend="g-spawn-async-with-pipes">g_spawn_async_with_pipes</link>(). It is called in the child after GLib has performed all the setup it plans to perform but before calling <function><link linkend="exec">exec</link>()</function>. Obviously, actions taken in this function will only affect the child, not the parent.</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>user_data</parameter> :</entry><entry>user data to pass to the function.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-spawn-async-with-pipes">g_spawn_async_with_pipes ()</title><programlisting><link linkend="gboolean">gboolean</link> g_spawn_async_with_pipes (const <link linkend="gchar">gchar</link> *working_directory, <link linkend="gchar">gchar</link> **argv, <link linkend="gchar">gchar</link> **envp, <link linkend="GSpawnFlags">GSpawnFlags</link> flags, <link linkend="GSpawnChildSetupFunc">GSpawnChildSetupFunc</link> child_setup, <link linkend="gpointer">gpointer</link> user_data, <link linkend="gint">gint</link> *child_pid, <link linkend="gint">gint</link> *standard_input, <link linkend="gint">gint</link> *standard_output, <link linkend="gint">gint</link> *standard_error, <link linkend="GError">GError</link> **error);</programlisting><para>Executes a child program asynchronously (your program will notblock waiting for the child to exit). The child program isspecified by the only argument that must be provided, <parameter>argv</parameter>. <parameter>argv</parameter>should be a <literal>NULL</literal>-terminated array of strings, to be passed as theargument vector for the child. The first string in <parameter>argv</parameter> is ofcourse the name of the program to execute. By default, the name ofthe program must be a full path; the <envar>PATH</envar> shell variable will only be searched if you pass the <literal>G_SPAWN_SEARCH_PATH</literal> flag.</para><para><parameter>envp</parameter> is a <literal>NULL</literal>-terminated array of strings, where each stringhas the form <literal>KEY=VALUE</literal>. This will becomethe child's environment. If <parameter>envp</parameter> is <literal>NULL</literal>, the child inherits itsparent's environment.</para><para><parameter>flags</parameter> should be the bitwise OR of any flags you want to affect thefunction's behavior. The <literal>G_SPAWN_DO_NOT_REAP_CHILD</literal> means that thechild will not be automatically reaped; you must call <function><link linkend="waitpid">waitpid</link>()</function> or handle <literal>SIGCHLD</literal> yourself, or the child will become a zombie.<literal>G_SPAWN_LEAVE_DESCRIPTORS_OPEN</literal> means that the parent's open filedescriptors will be inherited by the child; otherwise alldescriptors except stdin/stdout/stderr will be closed beforecalling <function><link linkend="exec">exec</link>()</function> in the child. <literal>G_SPAWN_SEARCH_PATH</literal> means that <literal>argv[0]</literal> need not be an absolute path, itwill be looked for in the user's <envar>PATH</envar>. <literal>G_SPAWN_STDOUT_TO_DEV_NULL</literal> means that the child's standad output will be discarded, instead of going to the same location as the parent's standard output.<literal>G_SPAWN_STDERR_TO_DEV_NULL</literal> means that the child's standard errorwill be discarded. <literal>G_SPAWN_CHILD_INHERITS_STDIN</literal> means thatthe child will inherit the parent's standard input (by default,the child's standard input is attached to /dev/null).<literal>G_SPAWN_FILE_AND_ARGV_ZERO</literal> means that the first element of <parameter>argv</parameter> isthe file to execute, while the remaining elements are theactual argument vector to pass to the file. Normally<link linkend="g-spawn-async-with-pipes">g_spawn_async_with_pipes</link>() uses <parameter>argv</parameter>[0] as the file to execute, andpasses all of <parameter>argv</parameter> to the child.</para><para><parameter>child_setup</parameter> and <parameter>user_data</parameter> are a function and user data to becalled in the child after GLib has performed all the setup it plansto perform (including creating pipes, closing file descriptors,etc.) but before calling <function><link linkend="exec">exec</link>()</function>. That is, <parameter>child_setup</parameter> is called just before calling <function><link linkend="exec">exec</link>()</function> in the child. Obviously actions taken in this function will only affect the child, not the parent. </para><para>If non-<literal>NULL</literal>, <parameter>child_pid</parameter> will be filled with the child's processID. You can use the process ID to send signals to the child, orto <function><link linkend="waitpid">waitpid</link>()</function> if you specified the <literal>G_SPAWN_DO_NOT_REAP_CHILD</literal> flag.</para><para>If non-<literal>NULL</literal>, the <parameter>standard_input</parameter>, <parameter>standard_output</parameter>, <parameter>standard_error</parameter>locations will be filled with file descriptors for writing to the child'sstandard input or reading from its standard output or standard error.The caller of <link linkend="g-spawn-async-with-pipes">g_spawn_async_with_pipes</link>() must close these file descriptorswhen they are no longer in use. If these parameters are <literal>NULL</literal>, thecorresponding pipe won't be created.</para><para><parameter>error</parameter> can be <literal>NULL</literal> to ignore errors, or non-<literal>NULL</literal> to report errors.If an error is set, the function returns <literal>FALSE</literal>. Errorsare reported even if they occur in the child (for example if theexecutable in <literal>argv[0]</literal> is not found). Typicallythe <literal>message</literal> field of returned errors should be displayedto users. Possible errors are those from the <link linkend="G-SPAWN-ERROR-CAPS">G_SPAWN_ERROR</link> domain.</para><para>If an error occurs, <parameter>child_pid</parameter>, <parameter>standard_input</parameter>, <parameter>standard_output</parameter>,and <parameter>standard_error</parameter> will not be filled with valid values.</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>working_directory</parameter> :</entry><entry> child's current working directory, or <literal>NULL</literal> to inherit parent's</entry></row><row><entry align="right"><parameter>argv</parameter> :</entry><entry> child's argument vector</entry></row><row><entry align="right"><parameter>envp</parameter> :</entry><entry> child's environment, or <literal>NULL</literal> to inherit parent's</entry></row><row><entry align="right"><parameter>flags</parameter> :</entry><entry> flags from <link linkend="GSpawnFlags">GSpawnFlags</link></entry></row><row><entry align="right"><parameter>child_setup</parameter> :</entry><entry> function to run in the child just before <function><link linkend="exec">exec</link>()</function></entry></row><row><entry align="right"><parameter>user_data</parameter> :</entry>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -