[wxMSW 2.8.0] wxExecute Issues
Seth Manley
samofvt at hotmail.com
Fri Mar 9 14:17:49 PST 2007
I'm have wxUSE_STREAMS = 1 and i'm using the common function
long wxExecute(const wxString& command, wxArrayString& output,
wxArrayString& errors, int flags = 0)
Two issues with the implementation:
1) When the return code of the process is "-1", neither stderr nor stdout is
captured (See ($WXWIN)/src/common/utilscmn.cpp,
wxDoExecuteWithCapture(...), Line ~690). The problem is that some processes
return -1 just to indicate an error was encountered, not nesssarily that it
crashed. I don't know if there's any reason not to try to capute whatever
is in 'stderr' or 'stdout'.
2) In ($WXWIN)/src/common/utilscmn.cpp, ReadAll(...), Line ~651, if there
was only one line of output to the stream with no cr/lf, the function was
not capturing it. I've modiified it as follows (below <code>), and so far
it works (only some testing though).
Thanks,
Seth
<code>
#if wxUSE_STREAMS
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);
wxString line;
bool cont = true;
while ( cont )
{
if ( !*is )
{
cont = false;
}
else if( is->Eof() )
{
break;
}
else
{
line = tis.ReadLine();
// omit the last line if it is empty, also gets rid of the
problem
// of capturing a line if there was no output on that stream
if(is->Eof() && line.IsEmpty())
break;
else
output.Add(line);
}
}
return cont;
}
#endif // wxUSE_STREAMS
</code>
_________________________________________________________________
Play Flexicon: the crossword game that feeds your brain. PLAY now for FREE.
http://zone.msn.com/en/flexicon/default.htm?icid=flexicon_hmtagline
More information about the wx-users
mailing list