From 1885d4d4e2490df11223f0f4662487b158217ed6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 30 Apr 2007 01:17:43 +0000 Subject: [PATCH] don't drop lines without trailing new line character in wxExecute() with capture [backport from HEAD] git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@45714 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/common/utilscmn.cpp | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 38c7e05575..516fc6a37e 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -94,6 +94,7 @@ Major new features in 2.8 release All: - Fix bug in wxFileConfig when recreating a group (Steven Van Ingelgem) +- Account for lines without newline at the end in wxExecute() - Added wxString::char_str() and wchar_str() methods for forward compatiblity with wxWidgets 3 diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index 7cf1062a5f..732b244072 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -647,24 +647,27 @@ static bool ReadAll(wxInputStream *is, wxArrayString& output) wxTextInputStream tis(*is); - bool cont = true; - while ( cont ) + for ( ;; ) { wxString line = tis.ReadLine(); - if ( is->Eof() ) - break; + // check for EOF before other errors as it's not really an error + if ( is->Eof() ) + { + // add the last, possibly incomplete, line + if ( !line.empty() ) + output.Add(line); + break; + } + + // any other error is fatal if ( !*is ) - { - cont = false; - } - else - { - output.Add(line); - } + return false; + + output.Add(line); } - return cont; + return true; } #endif // wxUSE_STREAMS