+#endif // wxUSE_STREAMS
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// process termination detecting support
+// ----------------------------------------------------------------------------
+
+// thread function for the thread monitoring the process termination
+static DWORD __stdcall wxExecuteThread(void *arg)
+{
+ wxExecuteData * const data = (wxExecuteData *)arg;
+
+ // create the shutdown event if we're the first thread starting to wait
+ if ( !gs_heventShutdown )
+ {
+ // create a manual initially non-signalled event object
+ gs_heventShutdown = ::CreateEvent(NULL, TRUE, FALSE, NULL);
+ if ( !gs_heventShutdown )
+ {
+ wxLogDebug(wxT("CreateEvent() in wxExecuteThread failed"));
+ }
+ }
+
+ HANDLE handles[2] = { data->hProcess, gs_heventShutdown };
+ switch ( ::WaitForMultipleObjects(2, handles, FALSE, INFINITE) )
+ {
+ case WAIT_OBJECT_0:
+ // process terminated, get its exit code
+ if ( !::GetExitCodeProcess(data->hProcess, &data->dwExitCode) )
+ {
+ wxLogLastError(wxT("GetExitCodeProcess"));
+ }
+
+ wxASSERT_MSG( data->dwExitCode != STILL_ACTIVE,
+ wxT("process should have terminated") );
+
+ // send a message indicating process termination to the window
+ ::SendMessage(data->hWnd, wxWM_PROC_TERMINATED, 0, (LPARAM)data);
+ break;
+
+ case WAIT_OBJECT_0 + 1:
+ // we're shutting down but the process is still running -- leave it
+ // run but clean up the associated data
+ if ( !data->state )
+ {
+ delete data;
+ }
+ //else: exiting while synchronously executing process is still
+ // running? this shouldn't happen...
+ break;
+
+ default:
+ wxLogDebug(wxT("Waiting for the process termination failed!"));
+ }
+
+ return 0;
+}
+
+// window procedure of a hidden window which is created just to receive
+// the notification message when a process exits
+LRESULT APIENTRY _EXPORT wxExecuteWindowCbk(HWND hWnd, UINT message,
+ WPARAM wParam, LPARAM lParam)
+{
+ if ( message == wxWM_PROC_TERMINATED )
+ {
+ DestroyWindow(hWnd); // we don't need it any more
+
+ wxExecuteData * const data = (wxExecuteData *)lParam;
+ if ( data->handler )
+ {
+ data->handler->OnTerminate((int)data->dwProcessId,
+ (int)data->dwExitCode);
+ }
+
+ if ( data->state )
+ {
+ // we're executing synchronously, tell the waiting thread
+ // that the process finished
+ data->state = false;
+ }
+ else
+ {
+ // asynchronous execution - we should do the clean up
+ delete data;
+ }
+
+ return 0;
+ }
+ else
+ {
+ return ::DefWindowProc(hWnd, message, wParam, lParam);
+ }
+}
+
+// ============================================================================
+// implementation of IO redirection support classes
+// ============================================================================
+
+#if wxUSE_STREAMS && !defined(__WXWINCE__)
+
+// ----------------------------------------------------------------------------
+// wxPipeInputStreams
+// ----------------------------------------------------------------------------