X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9978ac8e4f52e47a07c146cfa17ba69bf2cc0338..f369c7c2841c0534424f2c184783c1a2070012cf:/src/msw/utilsexc.cpp?ds=sidebyside diff --git a/src/msw/utilsexc.cpp b/src/msw/utilsexc.cpp index a675969f7e..7c085553ed 100644 --- a/src/msw/utilsexc.cpp +++ b/src/msw/utilsexc.cpp @@ -433,8 +433,19 @@ wxPipeInputStream::~wxPipeInputStream() bool wxPipeInputStream::CanRead() const { + // we can read if there's something in the put back buffer + // even pipe is closed + if ( m_wbacksize > m_wbackcur ) + return true; + + wxPipeInputStream * const self = wxConstCast(this, wxPipeInputStream); + if ( !IsOpened() ) + { + // set back to mark Eof as it may have been unset by Ungetch() + self->m_lasterror = wxSTREAM_EOF; return false; + } DWORD nAvailable; @@ -460,8 +471,6 @@ bool wxPipeInputStream::CanRead() const // it had been closed ::CloseHandle(m_hInput); - wxPipeInputStream *self = wxConstCast(this, wxPipeInputStream); - self->m_hInput = INVALID_HANDLE_VALUE; self->m_lasterror = wxSTREAM_EOF; @@ -987,13 +996,13 @@ long wxExecute(const wxString& cmd, int flags, wxProcess *handler) while ( data->state ) { #if wxUSE_STREAMS && !defined(__WXWINCE__) - bufOut.Update(); - bufErr.Update(); + if ( !bufOut.Update() && !bufErr.Update() ) #endif // wxUSE_STREAMS - - // don't eat 100% of the CPU -- ugly but anything else requires - // real async IO which we don't have for the moment - ::Sleep(50); + { + // don't eat 100% of the CPU -- ugly but anything else requires + // real async IO which we don't have for the moment + ::Sleep(50); + } // we must process messages or we'd never get wxWM_PROC_TERMINATED traits->AlwaysYield(); @@ -1012,18 +1021,47 @@ long wxExecute(const wxString& cmd, int flags, wxProcess *handler) return dwExitCode; } -long wxExecute(wxChar **argv, int flags, wxProcess *handler) +template +long wxExecuteImpl(CharType **argv, int flags, wxProcess *handler) { wxString command; + command.reserve(1024); + wxString arg; for ( ;; ) { - command += *argv++; + arg = *argv++; + + // escape any quotes present in the string to avoid interfering with + // the command line parsing in the child process + arg.Replace("\"", "\\\"", true /* replace all */); + + // and quote any arguments containing the spaces to prevent them from + // being broken down + if ( arg.find_first_of(" \t") == wxString::npos ) + command += arg; + else + command += '\"' + arg + '\"'; + if ( !*argv ) break; - command += _T(' '); + command += ' '; } return wxExecute(command, flags, handler); } + +long wxExecute(char **argv, int flags, wxProcess *handler) +{ + return wxExecuteImpl(argv, flags, handler); +} + +#if wxUSE_UNICODE + +long wxExecute(wchar_t **argv, int flags, wxProcess *handler) +{ + return wxExecuteImpl(argv, flags, handler); +} + +#endif // wxUSE_UNICODE