fixes to wxPipeInputStream
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17704 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -43,8 +43,7 @@ enum wxStreamError
|
|||||||
wxSTREAM_NO_ERROR = 0, // stream is in good state
|
wxSTREAM_NO_ERROR = 0, // stream is in good state
|
||||||
wxSTREAM_EOF, // EOF reached in Read() or similar
|
wxSTREAM_EOF, // EOF reached in Read() or similar
|
||||||
wxSTREAM_WRITE_ERROR, // generic write error
|
wxSTREAM_WRITE_ERROR, // generic write error
|
||||||
wxSTREAM_READ_ERROR, // generic read error
|
wxSTREAM_READ_ERROR // generic read error
|
||||||
wxSTREAM_PIPE_ERROR // broken pipe: the other half was closed
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// compatibility
|
// compatibility
|
||||||
|
@@ -122,8 +122,7 @@ void wxProcess::SetPipeStreams(wxInputStream *inputSstream,
|
|||||||
|
|
||||||
bool wxProcess::IsInputOpened() const
|
bool wxProcess::IsInputOpened() const
|
||||||
{
|
{
|
||||||
return m_inputStream &&
|
return m_inputStream && m_inputStream->GetLastError() != wxSTREAM_EOF;
|
||||||
m_inputStream->GetLastError() != wxSTREAM_PIPE_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxProcess::IsInputAvailable() const
|
bool wxProcess::IsInputAvailable() const
|
||||||
|
@@ -1062,6 +1062,38 @@ wxString wxGetCurrentDir()
|
|||||||
// wxExecute
|
// wxExecute
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// wxDoExecuteWithCapture() helper: reads an entire stream into one array
|
||||||
|
//
|
||||||
|
// returns TRUE if ok, FALSE if error
|
||||||
|
static bool ReadAll(wxInputStream *is, wxArrayString& output)
|
||||||
|
{
|
||||||
|
wxCHECK_MSG( is, FALSE, _T("NULL stream in wxExecute()?") );
|
||||||
|
|
||||||
|
// the stream could be already at EOF or in wxSTREAM_BROKEN_PIPE state
|
||||||
|
is->Reset();
|
||||||
|
|
||||||
|
wxTextInputStream tis(*is);
|
||||||
|
|
||||||
|
bool cont = TRUE;
|
||||||
|
while ( cont )
|
||||||
|
{
|
||||||
|
wxString line = tis.ReadLine();
|
||||||
|
if ( is->Eof() )
|
||||||
|
break;
|
||||||
|
|
||||||
|
if ( !*is )
|
||||||
|
{
|
||||||
|
cont = FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
output.Add(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cont;
|
||||||
|
}
|
||||||
|
|
||||||
// this is a private function because it hasn't a clean interface: the first
|
// this is a private function because it hasn't a clean interface: the first
|
||||||
// array is passed by reference, the second by pointer - instead we have 2
|
// array is passed by reference, the second by pointer - instead we have 2
|
||||||
// public versions of wxExecute() below
|
// public versions of wxExecute() below
|
||||||
@@ -1083,51 +1115,15 @@ static long wxDoExecuteWithCapture(const wxString& command,
|
|||||||
#if wxUSE_STREAMS
|
#if wxUSE_STREAMS
|
||||||
if ( rc != -1 )
|
if ( rc != -1 )
|
||||||
{
|
{
|
||||||
wxInputStream* is = process->GetInputStream();
|
if ( !ReadAll(process->GetInputStream(), output) )
|
||||||
wxCHECK_MSG( is, -1, _T("if wxExecute() succeded, stream can't be NULL") );
|
rc = -1;
|
||||||
wxTextInputStream tis(*is);
|
|
||||||
|
|
||||||
wxTextInputStream *tes = NULL;
|
|
||||||
wxInputStream *es = NULL;
|
|
||||||
if ( error )
|
if ( error )
|
||||||
{
|
{
|
||||||
es = process->GetErrorStream();
|
if ( !ReadAll(process->GetErrorStream(), *error) )
|
||||||
|
rc = -1;
|
||||||
wxCHECK_MSG( es, -1, _T("stderr can't be NULL") );
|
|
||||||
|
|
||||||
tes = new wxTextInputStream(*es);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cont;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
cont = FALSE;
|
|
||||||
|
|
||||||
if ( !is->Eof() && is->IsOk() )
|
|
||||||
{
|
|
||||||
wxString line = tis.ReadLine();
|
|
||||||
if ( !*is )
|
|
||||||
break;
|
|
||||||
|
|
||||||
cont = TRUE;
|
|
||||||
|
|
||||||
output.Add(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( error && !es->Eof() && es->IsOk() )
|
|
||||||
{
|
|
||||||
wxString line = tes->ReadLine();
|
|
||||||
if ( !*es )
|
|
||||||
break;
|
|
||||||
|
|
||||||
cont = TRUE;
|
|
||||||
|
|
||||||
error->Add(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while ( cont );
|
|
||||||
|
|
||||||
delete tes;
|
|
||||||
}
|
}
|
||||||
#endif // wxUSE_STREAMS
|
#endif // wxUSE_STREAMS
|
||||||
|
|
||||||
|
@@ -377,7 +377,7 @@ bool wxPipeInputStream::CanRead() const
|
|||||||
wxPipeInputStream *self = wxConstCast(this, wxPipeInputStream);
|
wxPipeInputStream *self = wxConstCast(this, wxPipeInputStream);
|
||||||
|
|
||||||
self->m_hInput = INVALID_HANDLE_VALUE;
|
self->m_hInput = INVALID_HANDLE_VALUE;
|
||||||
self->m_lasterror = wxSTREAM_PIPE_ERROR;
|
self->m_lasterror = wxSTREAM_EOF;
|
||||||
|
|
||||||
nAvailable = 0;
|
nAvailable = 0;
|
||||||
}
|
}
|
||||||
@@ -388,6 +388,13 @@ bool wxPipeInputStream::CanRead() const
|
|||||||
|
|
||||||
size_t wxPipeInputStream::OnSysRead(void *buffer, size_t len)
|
size_t wxPipeInputStream::OnSysRead(void *buffer, size_t len)
|
||||||
{
|
{
|
||||||
|
if ( !IsOpened() )
|
||||||
|
{
|
||||||
|
m_lasterror = wxSTREAM_EOF;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
DWORD bytesRead;
|
DWORD bytesRead;
|
||||||
if ( !::ReadFile(m_hInput, buffer, len, &bytesRead, NULL) )
|
if ( !::ReadFile(m_hInput, buffer, len, &bytesRead, NULL) )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user