Kludge popen/pclose calls on MS-Win

For MS Visual Studio we need to use _popen() and _pclose() instead of
the POSIX functions; and the pipe needs to be opened in binary mode.

Change-Id: Ide0fb26a1e5f121b384b0baaf8100f26c614ccc6
Fixes: QTBUG-73810
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
Dmitry Sokolov 2019-02-14 11:12:18 +01:00 committed by Edward Welbourne
parent 36a294d1aa
commit 55e31e6389

View File

@ -43,6 +43,15 @@
#include <QRegExp>
#include <algorithm>
#ifdef Q_CC_MSVC
#define popen _popen
#define QT_POPEN_READ "rb"
#define pclose _pclose
#else
#define QT_POPEN_READ "r"
#endif
static const bool mustReadOutputAnyway = true; // pclose seems to return the wrong error code unless we read the output
void deleteRecursively(const QString &dirName)
@ -70,7 +79,7 @@ FILE *openProcess(const QString &command)
QString processedCommand = command;
#endif
return popen(processedCommand.toLocal8Bit().constData(), "r");
return popen(processedCommand.toLocal8Bit().constData(), QT_POPEN_READ);
}
struct QtDependency
@ -1721,7 +1730,7 @@ bool scanImports(Options *options, QSet<QString> *usedDependencies)
.arg(shellQuote(rootPath))
.arg(importPaths.join(QLatin1Char(' ')));
FILE *qmlImportScannerCommand = popen(qmlImportScanner.toLocal8Bit().constData(), "r");
FILE *qmlImportScannerCommand = popen(qmlImportScanner.toLocal8Bit().constData(), QT_POPEN_READ);
if (qmlImportScannerCommand == 0) {
fprintf(stderr, "Couldn't run qmlimportscanner.\n");
return false;
@ -2160,7 +2169,7 @@ bool createAndroidProject(const Options &options)
if (options.verbose)
fprintf(stdout, " -- Command: %s\n", qPrintable(androidTool));
FILE *androidToolCommand = popen(androidTool.toLocal8Bit().constData(), "r");
FILE *androidToolCommand = popen(androidTool.toLocal8Bit().constData(), QT_POPEN_READ);
if (androidToolCommand == 0) {
fprintf(stderr, "Cannot run command '%s'\n", qPrintable(androidTool));
return false;