[wxMSW 2.8.0] wxExecute Issues

Vadim Zeitlin vadim at wxwindows.org
Sun Apr 29 18:22:16 PDT 2007


On Fri, 09 Mar 2007 17:17:49 -0500 Seth Manley <samofvt at hotmail.com> wrote:

SM> Two issues with the implementation:

 Hello,

 I wanted to deal with this before 2.8.4 release so I looked at these
issues in more details:

SM> 1) When the return code of the process is "-1", neither stderr nor stdout is 
SM> captured (See  ($WXWIN)/src/common/utilscmn.cpp, 
SM> wxDoExecuteWithCapture(...), Line ~690).  The problem is that some processes 
SM> return -1 just to indicate an error was encountered, not nesssarily that it 
SM> crashed.  I don't know if there's any reason not to try to capute whatever 
SM> is in 'stderr' or 'stdout'.

 The problem is that -1 is used as a special return value indicating error
and you shouldn't be getting it for _any_ process exit code. For example,
if you process is the result of the compilation of the following C program

	int main() { return -1; }

you should be getting 255 from wxExecute(), not -1. So how exactly can I
see this problem?

SM> 2) In ($WXWIN)/src/common/utilscmn.cpp, ReadAll(...), Line ~651, if there 
SM> was only one line of output to the stream with no cr/lf, the function was 
SM> not capturing it.

 Yes, there was indeed a bug here, thanks for finding it.

SM> I've modiified it as follows (below <code>), and so far it works (only
SM> some testing though).
...
SM> #if wxUSE_STREAMS
SM> static bool ReadAll(wxInputStream *is, wxArrayString& output)
SM> {
SM>     wxCHECK_MSG( is, false, _T("NULL stream in wxExecute()?") );
SM> 
SM>     // the stream could be already at EOF or in wxSTREAM_BROKEN_PIPE state
SM>     is->Reset();
SM> 
SM>     wxTextInputStream tis(*is);
SM> 
SM>     wxString line;
SM>     bool cont = true;
SM>     while ( cont )
SM>     {
SM> 
SM>         if ( !*is )
SM>         {
SM>             cont = false;
SM>         }
SM>         else if( is->Eof() )
SM>         {
SM>            break;
SM>         }
SM>         else
SM>         {
SM>             line = tis.ReadLine();
SM>             // omit the last line if it is empty, also gets rid of the 
SM> problem
SM>             // of capturing a line if there was no output on that stream
SM>             if(is->Eof() && line.IsEmpty())
SM>               break;
SM>             else
SM>               output.Add(line);
SM>         }
SM> 
SM>     }
SM> 
SM>     return cont;
SM> }
SM> #endif // wxUSE_STREAMS

 This doesn't really work for me though because the first condition (!*is)
is true when the stream is at EOF. I've corrected it in a similar way and
it does seem to work for me correctly in all cases now. Please let us know
if you still have any problems with 2.8.4 in this respect.

 Thanks,
VZ

-- 
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/





More information about the wx-users mailing list