Work around wrong return code from pclose
authorPaul Olav Tvete <paul.tvete@digia.com>
Tue, 24 Sep 2013 08:32:32 +0000 (10:32 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 25 Sep 2013 09:40:10 +0000 (11:40 +0200)
When we do not read the process output, pclose returns an error code even
if the process completes successfully. The simple fix is to always
read the output, even if we don't need it.

Change-Id: Idaec75acbdea6a911aede04506cbd403120b3d92
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
src/androiddeployqt/main.cpp

index da4807b..454ad31 100644 (file)
@@ -54,6 +54,8 @@
 #include <QStandardPaths>
 #include <QUuid>
 
+static const bool mustReadOutputAnyway = true; // pclose seems to return the wrong error code unless we read the output
+
 void deleteRecursively(const QString &dirName)
 {
     QDir dir(dirName);
@@ -1560,10 +1562,11 @@ bool uninstallApk(const Options &options)
     if (adbCommand == 0)
         return false;
 
-    if (options.verbose) {
+    if (options.verbose || mustReadOutputAnyway) {
         char buffer[512];
         while (fgets(buffer, sizeof(buffer), adbCommand) != 0)
-            fprintf(stdout, "%s", buffer);
+            if (options.verbose)
+                fprintf(stdout, "%s", buffer);
     }
 
     int returnCode = pclose(adbCommand);
@@ -1604,10 +1607,11 @@ bool installApk(const Options &options)
     if (adbCommand == 0)
         return false;
 
-    if (options.verbose) {
+    if (options.verbose || mustReadOutputAnyway) {
         char buffer[512];
         while (fgets(buffer, sizeof(buffer), adbCommand) != 0)
-            fprintf(stdout, "%s", buffer);
+            if (options.verbose)
+                fprintf(stdout, "%s", buffer);
     }
 
     int returnCode = pclose(adbCommand);