From cefaa2ff4c1d206c6daaba995d5c3572d089ac00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Arve=20S=C3=A6ther?= Date: Wed, 19 Jun 2019 11:15:41 +0200 Subject: [PATCH] Fix androidtestrunner for windows First, we cannot quote the whole command in double quotes, since the command itself very often have double quotes inside it. Secondly, we should use the same that the ssh(1) command does: Instead of adb shell setprop foo 'a b' we should use adb shell setprop foo "'a b'" as explained here: [https://developer.android.com/studio/command-line/adb#shellcommands] Last hunk in isRunning(): The pipe character got eaten by the shell if we used a single quote (so the stuff after the pipe (grep) was actually run locally). Switching to ssh-style quoting fixed that. Change-Id: I3075cdf8595ac2549cec8019f2cba79f77815e0b Reviewed-by: BogDan Vatra --- src/tools/androidtestrunner/main.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/tools/androidtestrunner/main.cpp b/src/tools/androidtestrunner/main.cpp index 043c827403f..bb69b7b9149 100644 --- a/src/tools/androidtestrunner/main.cpp +++ b/src/tools/androidtestrunner/main.cpp @@ -108,18 +108,12 @@ static Options g_options; static bool execCommand(const QString &command, QByteArray *output = nullptr, bool verbose = false) { -#if defined(Q_OS_WIN32) - QString processedCommand = QLatin1Char('\"') + command + QLatin1Char('\"'); -#else - const QString& processedCommand = command; -#endif - if (verbose) - fprintf(stdout, "Execute %s\n", processedCommand.toUtf8().constData()); - FILE *process = popen(processedCommand.toUtf8().constData(), QT_POPEN_READ); + fprintf(stdout, "Execute %s\n", command.toUtf8().constData()); + FILE *process = popen(command.toUtf8().constData(), QT_POPEN_READ); if (!process) { - fprintf(stderr, "Cannot execute command %s", qPrintable(processedCommand)); + fprintf(stderr, "Cannot execute command %s", qPrintable(command)); return false; } char buffer[512]; @@ -368,7 +362,7 @@ static bool parseTestArgs() g_options.testArgs += QStringLiteral(" -o output.%1,%1").arg(format); g_options.testArgs += unhandledArgs; - g_options.testArgs = QStringLiteral("shell am start -e applicationArguments \"%1\" -n %2/%3").arg(shellQuote(g_options.testArgs.trimmed()), + g_options.testArgs = QStringLiteral("shell am start -e applicationArguments \"'%1'\" -n %2/%3").arg(shellQuote(g_options.testArgs.trimmed()), g_options.package, g_options.activity); return true; @@ -376,8 +370,8 @@ static bool parseTestArgs() static bool isRunning() { QByteArray output; - if (!execCommand(QStringLiteral("%1 shell 'ps | grep \" %2\"'").arg(g_options.adbCommand, - shellQuoteUnix(g_options.package)), &output)) { + if (!execCommand(QStringLiteral("%1 shell \"ps | grep ' %2'\"").arg(g_options.adbCommand, + shellQuote(g_options.package)), &output)) { return false; }