+// wxExecute support
+// ----------------------------------------------------------------------------
+
+int wxAppTraits::WaitForChild(wxExecuteData& execData)
+{
+ wxConsoleEventLoop loop;
+ return RunLoopUntilChildExit(execData, loop);
+}
+
+// This function is common code for both console and GUI applications and used
+// by wxExecute() to wait for the child exit while dispatching events.
+//
+// Notice that it should not be used for all the other cases, e.g. when we
+// don't need to wait for the child (wxEXEC_ASYNC) or when the events must not
+// dispatched (wxEXEC_NOEVENTS).
+int
+wxAppTraits::RunLoopUntilChildExit(wxExecuteData& execData,
+ wxEventLoopBase& loop)
+{
+ // It is possible that wxExecuteData::OnExit() had already been called
+ // and reset the PID to 0, in which case we don't need to do anything
+ // at all.
+ if ( !execData.pid )
+ return execData.exitcode;
+
+#if wxUSE_STREAMS
+ // Monitor the child streams if necessary.
+ wxScopedPtr<wxEventLoopSourceHandler>
+ stdoutHandler,
+ stderrHandler;
+ if ( execData.IsRedirected() )
+ {
+ stdoutHandler.reset(new wxExecuteEventLoopSourceHandler
+ (
+ execData.fdOut, execData.bufOut
+ ));
+ stderrHandler.reset(new wxExecuteEventLoopSourceHandler
+ (
+ execData.fdErr, execData.bufErr
+ ));
+ }
+#endif // wxUSE_STREAMS
+
+ // Store the event loop in the data associated with the child
+ // process so that it could exit the loop when the child exits.
+ execData.syncEventLoop = &loop;
+
+ // And run it.
+ loop.Run();
+
+ // The exit code will have been set when the child termination was detected.
+ return execData.exitcode;
+}
+
+// ----------------------------------------------------------------------------
+// wxExecuteData