From b59f7c360e60e6d0f0b19f41dce11aeec511333a Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Tue, 1 Nov 2016 17:17:04 +0000 Subject: [PATCH] android: Fixed issue using single quoted command with adb_shell When using 'check_exit_code' and 'as_root' options for adb_shell with a command containing single quotes, the provided command was escaped twice which has now been avoided. --- devlib/utils/android.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/devlib/utils/android.py b/devlib/utils/android.py index a009456..533835c 100644 --- a/devlib/utils/android.py +++ b/devlib/utils/android.py @@ -334,14 +334,15 @@ def adb_shell(device, command, timeout=None, check_exit_code=False, _check_env() if as_root: command = 'echo \'{}\' | su'.format(escape_single_quotes(command)) - device_string = ' -s {}'.format(device) if device else '' + device_part = ['-s', device] if device else [] + device_string = ' {} {}'.format(*device_part) if device_part else '' full_command = 'adb{} shell "{}"'.format(device_string, escape_double_quotes(command)) logger.debug(full_command) if check_exit_code: - actual_command = "adb{} shell '({}); echo \"\n$?\"'".format(device_string, - escape_single_quotes(command)) - raw_output, error = check_output(actual_command, timeout, shell=True) + adb_shell_command = '({}); echo \"\n$?\"'.format(command) + actual_command = ['adb'] + device_part + ['shell', adb_shell_command] + raw_output, error = check_output(actual_command, timeout, shell=False) if raw_output: try: output, exit_code, _ = raw_output.rsplit(newline_separator, 2)