]> git.saurik.com Git - wxWidgets.git/commitdiff
Suppress error output from Unix system information functions.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 19 Mar 2013 02:55:31 +0000 (02:55 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 19 Mar 2013 02:55:31 +0000 (02:55 +0000)
Redirect stderr to /dev/null in wxGetCommandOutput() to avoid errors from the
shell if the command we're trying to run doesn't exist.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73681 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/unix/utilsunx.cpp

index 07a73e52662533ff683f00dd5d382fbe5fecc6d8..5b6caba63cdaa5dd302ff894f5ecd743e8698e83 100644 (file)
@@ -844,11 +844,16 @@ wxString wxGetUserHome( const wxString &user )
 // the trailing newline
 static wxString wxGetCommandOutput(const wxString &cmd)
 {
-    FILE *f = popen(cmd.ToAscii(), "r");
+    // Suppress stderr from the shell to avoid outputting errors if the command
+    // doesn't exist.
+    FILE *f = popen((cmd + "2>/dev/null").ToAscii(), "r");
     if ( !f )
     {
-        wxLogSysError(wxT("Executing \"%s\" failed"), cmd.c_str());
-        return wxEmptyString;
+        // Notice that this doesn't happen simply if the command doesn't exist,
+        // but only in case of some really catastrophic failure inside popen()
+        // so we should really notify the user about this as this is not normal.
+        wxLogSysError(wxT("Executing \"%s\" failed"), cmd);
+        return wxString();
     }
 
     wxString s;