Don't ignore child process output if it exits with -1 exit code.

While this code is used by us if the program couldn't be launched at all, it
doesn't mean that it didn't run as -1 could also be returned by the child
process to indicate an error after outputting something, so we should still
read its output in this case.

Closes #15205.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74352 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2013-07-03 00:33:04 +00:00
parent d6655d446d
commit d1c063b90f
3 changed files with 15 additions and 16 deletions

View File

@ -575,6 +575,7 @@ All:
wxEVT_COMMAND_MENU_SELECTED is now wxEVT_MENU (but the old name remains
available for compatibility) (Catalin Raceanu).
- Fix wxExecute() implementation under Unix (Rob Bresalier).
- Also fix reading output from children exiting with -1 () (Jonathan Dagresta).
- Add wxEvtHandler::CallAfter() method for asynchronous method calls.
- Add support for symlinks to wxFileName (David Hart).
- Add wxDIR_NO_FOLLOW flag for wxDir traversal (David Hart).

View File

@ -962,11 +962,8 @@ void MyFrame::OnExecWithRedirect(wxCommandEvent& WXUNUSED(event))
wxLogStatus("Command \"%s\" terminated after %ldms; exit code %d.",
cmd, sw.Time(), code);
if ( code != -1 )
{
ShowOutput(cmd, output, wxT("Output"));
ShowOutput(cmd, errors, wxT("Errors"));
}
ShowOutput(cmd, output, wxT("Output"));
ShowOutput(cmd, errors, wxT("Errors"));
}
else // async exec
{

View File

@ -618,13 +618,15 @@ bool wxGetEnvMap(wxEnvVariableHashMap *map)
// wxExecute
// ----------------------------------------------------------------------------
// wxDoExecuteWithCapture() helper: reads an entire stream into one array
// wxDoExecuteWithCapture() helper: reads an entire stream into one array if
// the stream is non-NULL (it doesn't do anything if it's NULL).
//
// returns true if ok, false if error
#if wxUSE_STREAMS
static bool ReadAll(wxInputStream *is, wxArrayString& output)
{
wxCHECK_MSG( is, false, wxT("NULL stream in wxExecute()?") );
if ( !is )
return true;
// the stream could be already at EOF or in wxSTREAM_BROKEN_PIPE state
is->Reset();
@ -671,17 +673,16 @@ static long wxDoExecuteWithCapture(const wxString& command,
long rc = wxExecute(command, wxEXEC_SYNC | flags, process, env);
#if wxUSE_STREAMS
if ( rc != -1 )
// Notice that while -1 indicates an error exit code for us, a program
// exiting with this code could still have written something to its stdout
// and, especially, stderr, so we still need to read from them.
if ( !ReadAll(process->GetInputStream(), output) )
rc = -1;
if ( error )
{
if ( !ReadAll(process->GetInputStream(), output) )
if ( !ReadAll(process->GetErrorStream(), *error) )
rc = -1;
if ( error )
{
if ( !ReadAll(process->GetErrorStream(), *error) )
rc = -1;
}
}
#else
wxUnusedVar(output);