⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glib-spawning-processes.html

📁 最新gtk中文资料集
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<a class="link" 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 errorwill be discarded, instead of going to the same location as the parent'sstandard error. If you use this flag, <em class="parameter"><code>standard_error</code></em> must be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.<a class="link" 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'sstandard input (by default, the child's standard input is attached to/dev/null). If you use this flag, <em class="parameter"><code>standard_input</code></em> must be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.<a class="link" 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> isthe file to execute, while the remaining elements are theactual argument vector to pass to the file. Normally<a class="link" 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, andpasses all of <em class="parameter"><code>argv</code></em> to the child.</p><p><em class="parameter"><code>child_setup</code></em> and <em class="parameter"><code>user_data</code></em> are a function and user data. On POSIXplatforms, the function is called in the child after GLib hasperformed all the setup it plans to perform (including creatingpipes, closing file descriptors, etc.) but before calling<code class="function">exec()</code>. That is, <em class="parameter"><code>child_setup</code></em> is called justbefore calling <code class="function">exec()</code> in the child. Obviouslyactions taken in this function will only affect the child, not theparent. On Windows, there is no separate <code class="function">fork()</code> and <code class="function">exec()</code>functionality. Child processes are created and run witha single API call, <code class="function">CreateProcess()</code>. <em class="parameter"><code>child_setup</code></em> iscalled in the parent process just before creating the childprocess. You should carefully consider what you do in <em class="parameter"><code>child_setup</code></em>if you intend your software to be portable to Windows.</p><p>If non-<a class="link" 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'sprocess ID. You can use the process ID to send signals to thechild, or to use <a class="link" href="glib-The-Main-Event-Loop.html#g-child-watch-add"><code class="function">g_child_watch_add()</code></a> (or <code class="function">waitpid()</code>) if you specified the<a class="link" 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 befilled with a handle to the child process only if you specified the<a class="link" 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 childprocess using the Win32 API, for example wait for its terminationwith the <code class="function">WaitFor*()</code> functions, or examine itsexit code with <code class="function">GetExitCodeProcess()</code>. You should close the handle with <code class="function">CloseHandle()</code> or <a class="link" href="glib-Spawning-Processes.html#g-spawn-close-pid"><code class="function">g_spawn_close_pid()</code></a> when you no longer need it.</p><p>If non-<a class="link" 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>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 <a class="link" href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a> must close these file descriptorswhen they are no longer in use. If these parameters are <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>, the correspondingpipe won't be created.</p><p>If <em class="parameter"><code>standard_input</code></em> is NULL, the child's standard input is attached to /dev/null unless <a class="link" href="glib-Spawning-Processes.html#G-SPAWN-CHILD-INHERITS-STDIN:CAPS"><code class="literal">G_SPAWN_CHILD_INHERITS_STDIN</code></a> is set.</p><p>If <em class="parameter"><code>standard_error</code></em> is NULL, the child's standard error goes to the same location as the parent's standard error unless <a class="link" 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.</p><p>If <em class="parameter"><code>standard_output</code></em> is NULL, the child's standard output goes to the same location as the parent's standard output unless <a class="link" 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.</p><p><em class="parameter"><code>error</code></em> can be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore errors, or non-<a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to report errors.If an error is set, the function returns <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a>. Errorsare reported even if they occur in the child (for example if theexecutable in <code class="literal">argv[0]</code> is not found). Typicallythe <code class="literal">message</code> field of returned errors should be displayedto users. Possible errors are those from the <a class="link" href="glib-Spawning-Processes.html#G-SPAWN-ERROR:CAPS"><span class="type">G_SPAWN_ERROR</span></a> domain.</p><p>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>,and <em class="parameter"><code>standard_error</code></em> will not be filled with valid values.</p><p>If <em class="parameter"><code>child_pid</code></em> is not <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> and an error does not occur then the returnedpid must be closed using <a class="link" href="glib-Spawning-Processes.html#g-spawn-close-pid"><code class="function">g_spawn_close_pid()</code></a>.</p><p></p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>If you are writing a GTK+ application, and the program you are spawning is a graphical application, too, then you maywant to use <ahref="/usr/share/gtk-doc/html/gdk/GdkScreen.html#gdk-spawn-on-screen-with-pipes"><code class="function">gdk_spawn_on_screen_with_pipes()</code></a> instead to ensure that the spawned program opens its windows no the right screen.</p></div><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>working_directory</code></em>&#160;:</span></p></td><td> child's current working directory, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to inherit parent's, in the GLib file name encoding</td></tr><tr><td><p><span class="term"><em class="parameter"><code>argv</code></em>&#160;:</span></p></td><td> child's argument vector, in the GLib file name encoding</td></tr><tr><td><p><span class="term"><em class="parameter"><code>envp</code></em>&#160;:</span></p></td><td> child's environment, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to inherit parent's, in the GLib file name encoding</td></tr><tr><td><p><span class="term"><em class="parameter"><code>flags</code></em>&#160;:</span></p></td><td> flags from <a class="link" href="glib-Spawning-Processes.html#GSpawnFlags"><span class="type">GSpawnFlags</span></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>child_setup</code></em>&#160;:</span></p></td><td> function to run in the child just before <code class="function">exec()</code></td></tr><tr><td><p><span class="term"><em class="parameter"><code>user_data</code></em>&#160;:</span></p></td><td> user data for <em class="parameter"><code>child_setup</code></em></td></tr><tr><td><p><span class="term"><em class="parameter"><code>child_pid</code></em>&#160;:</span></p></td><td> return location for child process ID, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>standard_input</code></em>&#160;:</span></p></td><td> return location for file descriptor to write to child's stdin, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>standard_output</code></em>&#160;:</span></p></td><td> return location for file descriptor to read child's stdout, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>standard_error</code></em>&#160;:</span></p></td><td> return location for file descriptor to read child's stderr, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>error</code></em>&#160;:</span></p></td><td> return location for error</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> on success, <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if an error was set</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3100648"></a><h3><a name="g-spawn-async"></a>g_spawn_async ()</h3><a class="indexterm" name="id3100661"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a>            g_spawn_async                       (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *working_directory,                                                         <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> **argv,                                                         <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> **envp,                                                         <a class="link" href="glib-Spawning-Processes.html#GSpawnFlags">GSpawnFlags</a> flags,                                                         <a class="link" href="glib-Spawning-Processes.html#GSpawnChildSetupFunc">GSpawnChildSetupFunc</a> child_setup,                                                         <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> user_data,                                                         <a class="link" href="glib-The-Main-Event-Loop.html#GPid">GPid</a> *child_pid,                                                         <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>See <a class="link" 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 functionsimply calls the <a class="link" href="glib-Spawning-Processes.html#g-spawn-async-with-pipes"><code class="function">g_spawn_async_with_pipes()</code></a> without any pipes.</p><p></p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>If you are writing a GTK+ application, and the program you are spawning is a graphical application, too, then you maywant to use <ahref="/usr/share/gtk-doc/html/gdk/GdkScreen.html#gdk-spawn-on-screen"><code class="function">gdk_spawn_on_screen()</code></a> instead to ensure that the spawned program opens its windows on the right screen.</p></div><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>working_directory</code></em>&#160;:</span></p></td><td> child's current working directory, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to inherit parent's</td></tr><tr><td><p><span class="term"><em class="parameter"><code>argv</code></em>&#160;:</span></p></td><td> child's argument vector</td></tr><tr><td><p><span class="term"><em class="parameter"><code>envp</code></em>&#160;:</span></p></td><td> child's environment, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to inherit parent's</td></tr><tr><td><p><span class="term"><em class="parameter"><code>flags</code></em>&#160;:</span></p></td><td> flags from <a class="link" href="glib-Spawning-Processes.html#GSpawnFlags"><span class="type">GSpawnFlags</span></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>child_setup</code></em>&#160;:</span></p></td><td> function to run in the child just before <code class="function">exec()</code></td></tr><tr><td><p><span class="term"><em class="parameter"><code>user_data</code></em>&#160;:</span></p></td><td> user data for <em class="parameter"><code>child_setup</code></em></td></tr><tr><td><p><span class="term"><em class="parameter"><code>child_pid</code></em>&#160;:</span></p></td><td> return location for child process ID, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>error</code></em>&#160;:</span></p></td><td> return location for error</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> on success, <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if error is set</td></tr></tbody></table></div></div>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -