1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/utilsexc.cpp
3 // Purpose: wxExecute implementation for MSW
4 // Author: Julian Smart
8 // Copyright: (c) 1998-2002 wxWidgets dev team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
33 #include "wx/stream.h"
35 #include "wx/module.h"
38 #include "wx/process.h"
39 #include "wx/thread.h"
40 #include "wx/apptrait.h"
41 #include "wx/vector.h"
44 #include "wx/msw/private.h"
48 #if !defined(__GNUWIN32__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
55 #if defined(__GNUWIN32__)
56 #include <sys/unistd.h>
60 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
74 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
81 #include "wx/dde.h" // for WX_DDE hack in wxExecute
84 // implemented in utils.cpp
85 extern "C" WXDLLIMPEXP_BASE HWND
86 wxCreateHiddenWindow(LPCTSTR
*pclassname
, LPCTSTR classname
, WNDPROC wndproc
);
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 // this message is sent when the process we're waiting for terminates
93 #define wxWM_PROC_TERMINATED (WM_USER + 10000)
95 // ----------------------------------------------------------------------------
96 // this module globals
97 // ----------------------------------------------------------------------------
99 // we need to create a hidden window to receive the process termination
100 // notifications and for this we need a (Win) class name for it which we will
101 // register the first time it's needed
102 static const wxChar
*wxMSWEXEC_WNDCLASSNAME
= wxT("_wxExecute_Internal_Class");
103 static const wxChar
*gs_classForHiddenWindow
= NULL
;
105 // event used to wake up threads waiting in wxExecuteThread
106 static HANDLE gs_heventShutdown
= NULL
;
108 // handles of all threads monitoring the execution of asynchronously running
110 static wxVector
<HANDLE
> gs_asyncThreads
;
112 // ----------------------------------------------------------------------------
114 // ----------------------------------------------------------------------------
116 // structure describing the process we're being waiting for
122 if ( !::CloseHandle(hProcess
) )
124 wxLogLastError(wxT("CloseHandle(hProcess)"));
128 HWND hWnd
; // window to send wxWM_PROC_TERMINATED to
129 HANDLE hProcess
; // handle of the process
130 DWORD dwProcessId
; // pid of the process
132 DWORD dwExitCode
; // the exit code of the process
133 bool state
; // set to false when the process finishes
136 class wxExecuteModule
: public wxModule
139 virtual bool OnInit() { return true; }
140 virtual void OnExit()
142 if ( gs_heventShutdown
)
144 // stop any threads waiting for the termination of asynchronously
146 if ( !::SetEvent(gs_heventShutdown
) )
148 wxLogDebug(_T("Failed to set shutdown event in wxExecuteModule"));
151 ::CloseHandle(gs_heventShutdown
);
152 gs_heventShutdown
= NULL
;
154 // now wait until they terminate
155 if ( !gs_asyncThreads
.empty() )
157 const size_t numThreads
= gs_asyncThreads
.size();
159 if ( ::WaitForMultipleObjects
163 TRUE
, // wait for all of them to become signalled
164 3000 // long but finite value
167 wxLogDebug(_T("Failed to stop all wxExecute monitor threads"));
170 for ( size_t n
= 0; n
< numThreads
; n
++ )
172 ::CloseHandle(gs_asyncThreads
[n
]);
175 gs_asyncThreads
.clear();
179 if ( gs_classForHiddenWindow
)
181 if ( !::UnregisterClass(wxMSWEXEC_WNDCLASSNAME
, wxGetInstance()) )
183 wxLogLastError(_T("UnregisterClass(wxExecClass)"));
186 gs_classForHiddenWindow
= NULL
;
191 DECLARE_DYNAMIC_CLASS(wxExecuteModule
)
194 IMPLEMENT_DYNAMIC_CLASS(wxExecuteModule
, wxModule
)
196 #if wxUSE_STREAMS && !defined(__WXWINCE__)
198 // ----------------------------------------------------------------------------
200 // ----------------------------------------------------------------------------
202 class wxPipeInputStream
: public wxInputStream
205 wxPipeInputStream(HANDLE hInput
);
206 virtual ~wxPipeInputStream();
208 // returns true if the pipe is still opened
209 bool IsOpened() const { return m_hInput
!= INVALID_HANDLE_VALUE
; }
211 // returns true if there is any data to be read from the pipe
212 virtual bool CanRead() const;
215 size_t OnSysRead(void *buffer
, size_t len
);
220 wxDECLARE_NO_COPY_CLASS(wxPipeInputStream
);
223 class wxPipeOutputStream
: public wxOutputStream
226 wxPipeOutputStream(HANDLE hOutput
);
227 virtual ~wxPipeOutputStream() { Close(); }
231 size_t OnSysWrite(const void *buffer
, size_t len
);
236 wxDECLARE_NO_COPY_CLASS(wxPipeOutputStream
);
239 // define this to let wxexec.cpp know that we know what we're doing
240 #define _WX_USED_BY_WXEXECUTE_
241 #include "../common/execcmn.cpp"
243 // ----------------------------------------------------------------------------
244 // wxPipe represents a Win32 anonymous pipe
245 // ----------------------------------------------------------------------------
250 // the symbolic names for the pipe ends
257 // default ctor doesn't do anything
258 wxPipe() { m_handles
[Read
] = m_handles
[Write
] = INVALID_HANDLE_VALUE
; }
260 // create the pipe, return true if ok, false on error
263 // default secutiry attributes
264 SECURITY_ATTRIBUTES security
;
266 security
.nLength
= sizeof(security
);
267 security
.lpSecurityDescriptor
= NULL
;
268 security
.bInheritHandle
= TRUE
; // to pass it to the child
270 if ( !::CreatePipe(&m_handles
[0], &m_handles
[1], &security
, 0) )
272 wxLogSysError(_("Failed to create an anonymous pipe"));
280 // return true if we were created successfully
281 bool IsOk() const { return m_handles
[Read
] != INVALID_HANDLE_VALUE
; }
283 // return the descriptor for one of the pipe ends
284 HANDLE
operator[](Direction which
) const { return m_handles
[which
]; }
286 // detach a descriptor, meaning that the pipe dtor won't close it, and
288 HANDLE
Detach(Direction which
)
290 HANDLE handle
= m_handles
[which
];
291 m_handles
[which
] = INVALID_HANDLE_VALUE
;
296 // close the pipe descriptors
299 for ( size_t n
= 0; n
< WXSIZEOF(m_handles
); n
++ )
301 if ( m_handles
[n
] != INVALID_HANDLE_VALUE
)
303 ::CloseHandle(m_handles
[n
]);
304 m_handles
[n
] = INVALID_HANDLE_VALUE
;
309 // dtor closes the pipe descriptors
310 ~wxPipe() { Close(); }
316 #endif // wxUSE_STREAMS
318 // ============================================================================
320 // ============================================================================
322 // ----------------------------------------------------------------------------
323 // process termination detecting support
324 // ----------------------------------------------------------------------------
326 // thread function for the thread monitoring the process termination
327 static DWORD __stdcall
wxExecuteThread(void *arg
)
329 wxExecuteData
* const data
= (wxExecuteData
*)arg
;
331 // create the shutdown event if we're the first thread starting to wait
332 if ( !gs_heventShutdown
)
334 // create a manual initially non-signalled event object
335 gs_heventShutdown
= ::CreateEvent(NULL
, TRUE
, FALSE
, NULL
);
336 if ( !gs_heventShutdown
)
338 wxLogDebug(_T("CreateEvent() in wxExecuteThread failed"));
342 HANDLE handles
[2] = { data
->hProcess
, gs_heventShutdown
};
343 switch ( ::WaitForMultipleObjects(2, handles
, FALSE
, INFINITE
) )
346 // process terminated, get its exit code
347 if ( !::GetExitCodeProcess(data
->hProcess
, &data
->dwExitCode
) )
349 wxLogLastError(wxT("GetExitCodeProcess"));
352 wxASSERT_MSG( data
->dwExitCode
!= STILL_ACTIVE
,
353 wxT("process should have terminated") );
355 // send a message indicating process termination to the window
356 ::SendMessage(data
->hWnd
, wxWM_PROC_TERMINATED
, 0, (LPARAM
)data
);
359 case WAIT_OBJECT_0
+ 1:
360 // we're shutting down but the process is still running -- leave it
361 // run but clean up the associated data
366 //else: exiting while synchronously executing process is still
367 // running? this shouldn't happen...
371 wxLogDebug(_T("Waiting for the process termination failed!"));
377 // window procedure of a hidden window which is created just to receive
378 // the notification message when a process exits
379 LRESULT APIENTRY _EXPORT
wxExecuteWindowCbk(HWND hWnd
, UINT message
,
380 WPARAM wParam
, LPARAM lParam
)
382 if ( message
== wxWM_PROC_TERMINATED
)
384 DestroyWindow(hWnd
); // we don't need it any more
386 wxExecuteData
* const data
= (wxExecuteData
*)lParam
;
389 data
->handler
->OnTerminate((int)data
->dwProcessId
,
390 (int)data
->dwExitCode
);
395 // we're executing synchronously, tell the waiting thread
396 // that the process finished
401 // asynchronous execution - we should do the clean up
409 return ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
413 // ============================================================================
414 // implementation of IO redirection support classes
415 // ============================================================================
417 #if wxUSE_STREAMS && !defined(__WXWINCE__)
419 // ----------------------------------------------------------------------------
420 // wxPipeInputStreams
421 // ----------------------------------------------------------------------------
423 wxPipeInputStream::wxPipeInputStream(HANDLE hInput
)
428 wxPipeInputStream::~wxPipeInputStream()
430 if ( m_hInput
!= INVALID_HANDLE_VALUE
)
431 ::CloseHandle(m_hInput
);
434 bool wxPipeInputStream::CanRead() const
436 // we can read if there's something in the put back buffer
437 // even pipe is closed
438 if ( m_wbacksize
> m_wbackcur
)
441 wxPipeInputStream
* const self
= wxConstCast(this, wxPipeInputStream
);
445 // set back to mark Eof as it may have been unset by Ungetch()
446 self
->m_lasterror
= wxSTREAM_EOF
;
452 // function name is misleading, it works with anon pipes as well
453 DWORD rc
= ::PeekNamedPipe
456 NULL
, 0, // ptr to buffer and its size
457 NULL
, // [out] bytes read
458 &nAvailable
, // [out] bytes available
459 NULL
// [out] bytes left
464 if ( ::GetLastError() != ERROR_BROKEN_PIPE
)
467 wxLogLastError(_T("PeekNamedPipe"));
470 // don't try to continue reading from a pipe if an error occurred or if
471 // it had been closed
472 ::CloseHandle(m_hInput
);
474 self
->m_hInput
= INVALID_HANDLE_VALUE
;
475 self
->m_lasterror
= wxSTREAM_EOF
;
480 return nAvailable
!= 0;
483 size_t wxPipeInputStream::OnSysRead(void *buffer
, size_t len
)
487 m_lasterror
= wxSTREAM_EOF
;
493 if ( !::ReadFile(m_hInput
, buffer
, len
, &bytesRead
, NULL
) )
495 m_lasterror
= ::GetLastError() == ERROR_BROKEN_PIPE
497 : wxSTREAM_READ_ERROR
;
500 // bytesRead is set to 0, as desired, if an error occurred
504 // ----------------------------------------------------------------------------
505 // wxPipeOutputStream
506 // ----------------------------------------------------------------------------
508 wxPipeOutputStream::wxPipeOutputStream(HANDLE hOutput
)
512 // unblock the pipe to prevent deadlocks when we're writing to the pipe
513 // from which the child process can't read because it is writing in its own
515 DWORD mode
= PIPE_READMODE_BYTE
| PIPE_NOWAIT
;
516 if ( !::SetNamedPipeHandleState
520 NULL
, // collection count (we don't set it)
521 NULL
// timeout (we don't set it neither)
524 wxLogLastError(_T("SetNamedPipeHandleState(PIPE_NOWAIT)"));
528 bool wxPipeOutputStream::Close()
530 return ::CloseHandle(m_hOutput
) != 0;
534 size_t wxPipeOutputStream::OnSysWrite(const void *buffer
, size_t len
)
536 m_lasterror
= wxSTREAM_NO_ERROR
;
538 DWORD totalWritten
= 0;
542 if ( !::WriteFile(m_hOutput
, buffer
, len
, &chunkWritten
, NULL
) )
544 m_lasterror
= ::GetLastError() == ERROR_BROKEN_PIPE
546 : wxSTREAM_WRITE_ERROR
;
553 buffer
= (char *)buffer
+ chunkWritten
;
554 totalWritten
+= chunkWritten
;
561 #endif // wxUSE_STREAMS
563 // ============================================================================
564 // wxExecute functions family
565 // ============================================================================
569 // connect to the given server via DDE and ask it to execute the command
571 wxExecuteDDE(const wxString
& ddeServer
,
572 const wxString
& ddeTopic
,
573 const wxString
& ddeCommand
)
575 bool ok
wxDUMMY_INITIALIZE(false);
579 conn
= client
.MakeConnection(wxEmptyString
, ddeServer
, ddeTopic
);
584 else // connected to DDE server
586 // the added complication here is that although most programs use
587 // XTYP_EXECUTE for their DDE API, some important ones -- like Word
588 // and other MS stuff - use XTYP_REQUEST!
590 // moreover, anotheri mportant program (IE) understands both but
591 // returns an error from Execute() so we must try Request() first
592 // to avoid doing it twice
594 // we're prepared for this one to fail, so don't show errors
597 ok
= conn
->Request(ddeCommand
) != NULL
;
602 // now try execute -- but show the errors
603 ok
= conn
->Execute(ddeCommand
);
612 long wxExecute(const wxString
& cmd
, int flags
, wxProcess
*handler
)
614 wxCHECK_MSG( !cmd
.empty(), 0, wxT("empty command in wxExecute") );
617 // for many reasons, the code below breaks down if it's called from another
618 // thread -- this could be fixed, but as Unix versions don't support this
619 // neither I don't want to waste time on this now
620 wxASSERT_MSG( wxThread::IsMain(),
621 _T("wxExecute() can be called only from the main thread") );
622 #endif // wxUSE_THREADS
627 // DDE hack: this is really not pretty, but we need to allow this for
628 // transparent handling of DDE servers in wxMimeTypesManager. Usually it
629 // returns the command which should be run to view/open/... a file of the
630 // given type. Sometimes, however, this command just launches the server
631 // and an additional DDE request must be made to really open the file. To
632 // keep all this well hidden from the application, we allow a special form
633 // of command: WX_DDE#<command>#DDE_SERVER#DDE_TOPIC#DDE_COMMAND in which
634 // case we execute just <command> and process the rest below
635 wxString ddeServer
, ddeTopic
, ddeCommand
;
636 static const size_t lenDdePrefix
= 7; // strlen("WX_DDE:")
637 if ( cmd
.Left(lenDdePrefix
) == _T("WX_DDE#") )
639 // speed up the concatenations below
640 ddeServer
.reserve(256);
641 ddeTopic
.reserve(256);
642 ddeCommand
.reserve(256);
644 const wxChar
*p
= cmd
.c_str() + 7;
645 while ( *p
&& *p
!= _T('#') )
657 wxFAIL_MSG(_T("invalid WX_DDE command in wxExecute"));
660 while ( *p
&& *p
!= _T('#') )
672 wxFAIL_MSG(_T("invalid WX_DDE command in wxExecute"));
675 while ( *p
&& *p
!= _T('#') )
687 wxFAIL_MSG(_T("invalid WX_DDE command in wxExecute"));
695 // if we want to just launch the program and not wait for its
696 // termination, try to execute DDE command right now, it can succeed if
697 // the process is already running - but as it fails if it's not
698 // running, suppress any errors it might generate
699 if ( !(flags
& wxEXEC_SYNC
) )
702 if ( wxExecuteDDE(ddeServer
, ddeTopic
, ddeCommand
) )
704 // a dummy PID - this is a hack, of course, but it's well worth
705 // it as we don't open a new server each time we're called
706 // which would be quite bad
718 // the IO redirection is only supported with wxUSE_STREAMS
719 BOOL redirect
= FALSE
;
721 #if wxUSE_STREAMS && !defined(__WXWINCE__)
722 wxPipe pipeIn
, pipeOut
, pipeErr
;
724 // we'll save here the copy of pipeIn[Write]
725 HANDLE hpipeStdinWrite
= INVALID_HANDLE_VALUE
;
727 // open the pipes to which child process IO will be redirected if needed
728 if ( handler
&& handler
->IsRedirected() )
730 // create pipes for redirecting stdin, stdout and stderr
731 if ( !pipeIn
.Create() || !pipeOut
.Create() || !pipeErr
.Create() )
733 wxLogSysError(_("Failed to redirect the child process IO"));
735 // indicate failure: we need to return different error code
736 // depending on the sync flag
737 return flags
& wxEXEC_SYNC
? -1 : 0;
742 #endif // wxUSE_STREAMS
744 // create the process
749 #if wxUSE_STREAMS && !defined(__WXWINCE__)
752 si
.dwFlags
= STARTF_USESTDHANDLES
;
754 si
.hStdInput
= pipeIn
[wxPipe::Read
];
755 si
.hStdOutput
= pipeOut
[wxPipe::Write
];
756 si
.hStdError
= pipeErr
[wxPipe::Write
];
758 // when the std IO is redirected, we don't show the (console) process
759 // window by default, but this can be overridden by the caller by
760 // specifying wxEXEC_NOHIDE flag
761 if ( !(flags
& wxEXEC_NOHIDE
) )
763 si
.dwFlags
|= STARTF_USESHOWWINDOW
;
764 si
.wShowWindow
= SW_HIDE
;
767 // we must duplicate the handle to the write side of stdin pipe to make
768 // it non inheritable: indeed, we must close the writing end of pipeIn
769 // before launching the child process as otherwise this handle will be
770 // inherited by the child which will never close it and so the pipe
771 // will never be closed and the child will be left stuck in ReadFile()
772 HANDLE pipeInWrite
= pipeIn
.Detach(wxPipe::Write
);
773 if ( !::DuplicateHandle
775 ::GetCurrentProcess(),
777 ::GetCurrentProcess(),
779 0, // desired access: unused here
780 FALSE
, // not inherited
781 DUPLICATE_SAME_ACCESS
// same access as for src handle
784 wxLogLastError(_T("DuplicateHandle"));
787 ::CloseHandle(pipeInWrite
);
789 #endif // wxUSE_STREAMS
791 PROCESS_INFORMATION pi
;
792 DWORD dwFlags
= CREATE_SUSPENDED
;
795 dwFlags
|= CREATE_DEFAULT_ERROR_MODE
;
797 // we are assuming commands without spaces for now
798 wxString moduleName
= command
.BeforeFirst(wxT(' '));
799 wxString arguments
= command
.AfterFirst(wxT(' '));
802 bool ok
= ::CreateProcess
804 // WinCE requires appname to be non null
805 // Win32 allows for null
808 moduleName
.wx_str(),// application name
810 arguments
.wx_str(), // arguments
812 NULL
, // application name (use only cmd line)
814 command
.wx_str(), // full command line
816 NULL
, // security attributes: defaults for both
817 NULL
, // the process and its main thread
818 redirect
, // inherit handles if we use pipes
819 dwFlags
, // process creation flags
820 NULL
, // environment (use the same)
821 NULL
, // current directory (use the same)
822 &si
, // startup info (unused here)
826 #if wxUSE_STREAMS && !defined(__WXWINCE__)
827 // we can close the pipe ends used by child anyhow
830 ::CloseHandle(pipeIn
.Detach(wxPipe::Read
));
831 ::CloseHandle(pipeOut
.Detach(wxPipe::Write
));
832 ::CloseHandle(pipeErr
.Detach(wxPipe::Write
));
834 #endif // wxUSE_STREAMS
838 #if wxUSE_STREAMS && !defined(__WXWINCE__)
839 // close the other handles too
842 ::CloseHandle(pipeOut
.Detach(wxPipe::Read
));
843 ::CloseHandle(pipeErr
.Detach(wxPipe::Read
));
845 #endif // wxUSE_STREAMS
847 wxLogSysError(_("Execution of command '%s' failed"), command
.c_str());
849 return flags
& wxEXEC_SYNC
? -1 : 0;
852 #if wxUSE_STREAMS && !defined(__WXWINCE__)
853 // the input buffer bufOut is connected to stdout, this is why it is
854 // called bufOut and not bufIn
855 wxStreamTempInputBuffer bufOut
,
860 // We can now initialize the wxStreams
862 outStream
= new wxPipeInputStream(pipeOut
.Detach(wxPipe::Read
));
864 errStream
= new wxPipeInputStream(pipeErr
.Detach(wxPipe::Read
));
866 inStream
= new wxPipeOutputStream(hpipeStdinWrite
);
868 handler
->SetPipeStreams(outStream
, inStream
, errStream
);
870 bufOut
.Init(outStream
);
871 bufErr
.Init(errStream
);
873 #endif // wxUSE_STREAMS
875 // create a hidden window to receive notification about process
877 HWND hwnd
= wxCreateHiddenWindow
879 &gs_classForHiddenWindow
,
880 wxMSWEXEC_WNDCLASSNAME
,
881 (WNDPROC
)wxExecuteWindowCbk
884 wxASSERT_MSG( hwnd
, wxT("can't create a hidden window for wxExecute") );
887 wxExecuteData
*data
= new wxExecuteData
;
888 data
->hProcess
= pi
.hProcess
;
889 data
->dwProcessId
= pi
.dwProcessId
;
891 data
->state
= (flags
& wxEXEC_SYNC
) != 0;
892 if ( flags
& wxEXEC_SYNC
)
894 // handler may be !NULL for capturing program output, but we don't use
895 // it wxExecuteData struct in this case
896 data
->handler
= NULL
;
900 // may be NULL or not
901 data
->handler
= handler
;
904 handler
->SetPid(pi
.dwProcessId
);
908 HANDLE hThread
= ::CreateThread(NULL
,
915 // resume process we created now - whether the thread creation succeeded or
917 if ( ::ResumeThread(pi
.hThread
) == (DWORD
)-1 )
919 // ignore it - what can we do?
920 wxLogLastError(wxT("ResumeThread in wxExecute"));
923 // close unneeded handle
924 if ( !::CloseHandle(pi
.hThread
) )
925 wxLogLastError(wxT("CloseHandle(hThread)"));
929 wxLogLastError(wxT("CreateThread in wxExecute"));
934 // the process still started up successfully...
935 return pi
.dwProcessId
;
938 gs_asyncThreads
.push_back(hThread
);
940 #if wxUSE_IPC && !defined(__WXWINCE__)
941 // second part of DDE hack: now establish the DDE conversation with the
942 // just launched process
943 if ( !ddeServer
.empty() )
947 // give the process the time to init itself
949 // we use a very big timeout hoping that WaitForInputIdle() will return
950 // much sooner, but not INFINITE just in case the process hangs
951 // completely - like this we will regain control sooner or later
952 switch ( ::WaitForInputIdle(pi
.hProcess
, 10000 /* 10 seconds */) )
955 wxFAIL_MSG( _T("unexpected WaitForInputIdle() return code") );
959 wxLogLastError(_T("WaitForInputIdle() in wxExecute"));
962 wxLogDebug(_T("Timeout too small in WaitForInputIdle"));
968 // ok, process ready to accept DDE requests
969 ok
= wxExecuteDDE(ddeServer
, ddeTopic
, ddeCommand
);
974 wxLogDebug(_T("Failed to send DDE request to the process \"%s\"."),
980 if ( !(flags
& wxEXEC_SYNC
) )
982 // clean up will be done when the process terminates
985 return pi
.dwProcessId
;
988 wxAppTraits
*traits
= wxTheApp
? wxTheApp
->GetTraits() : NULL
;
989 wxCHECK_MSG( traits
, -1, _T("no wxAppTraits in wxExecute()?") );
992 if ( !(flags
& wxEXEC_NODISABLE
) )
994 // disable all app windows while waiting for the child process to finish
995 cookie
= traits
->BeforeChildWaitLoop();
998 // wait until the child process terminates
999 while ( data
->state
)
1001 #if wxUSE_STREAMS && !defined(__WXWINCE__)
1002 if ( !bufOut
.Update() && !bufErr
.Update() )
1003 #endif // wxUSE_STREAMS
1005 // don't eat 100% of the CPU -- ugly but anything else requires
1006 // real async IO which we don't have for the moment
1010 // we must process messages or we'd never get wxWM_PROC_TERMINATED
1011 traits
->AlwaysYield();
1014 if ( !(flags
& wxEXEC_NODISABLE
) )
1016 // reenable disabled windows back
1017 traits
->AfterChildWaitLoop(cookie
);
1020 DWORD dwExitCode
= data
->dwExitCode
;
1023 // return the exit code
1027 template <typename CharType
>
1028 long wxExecuteImpl(CharType
**argv
, int flags
, wxProcess
*handler
)
1031 command
.reserve(1024);
1041 // we need to quote empty arguments, otherwise they'd just
1047 // escape any quotes present in the string to avoid interfering
1048 // with the command line parsing in the child process
1049 arg
.Replace("\"", "\\\"", true /* replace all */);
1051 // and quote any arguments containing the spaces to prevent them from
1052 // being broken down
1053 quote
= arg
.find_first_of(" \t") != wxString::npos
;
1057 command
+= '\"' + arg
+ '\"';
1067 return wxExecute(command
, flags
, handler
);
1070 long wxExecute(char **argv
, int flags
, wxProcess
*handler
)
1072 return wxExecuteImpl(argv
, flags
, handler
);
1077 long wxExecute(wchar_t **argv
, int flags
, wxProcess
*handler
)
1079 return wxExecuteImpl(argv
, flags
, handler
);
1082 #endif // wxUSE_UNICODE