1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-02-20 20:09:11 +00:00

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.
This commit is contained in:
Marc Bonnici 2016-11-02 14:52:47 +00:00
parent 23eb357e9e
commit 2e1ce49170

View File

@ -282,13 +282,16 @@ def adb_shell(device, command, timeout=None, check_exit_code=False, as_root=Fals
_check_env()
if as_root:
command = 'echo \'{}\' | su'.format(escape_single_quotes(command))
device_string = '-s {}'.format(device) if device else ''
full_command = 'adb {} shell "{}"'.format(device_string, escape_double_quotes(command))
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))
adb_shell_command = '({}); echo \"\n$?\"'.format(command)
actual_command = ['adb'] + device_part + ['shell', adb_shell_command]
try:
raw_output, error = check_output(actual_command, timeout, shell=True)
raw_output, error = check_output(actual_command, timeout, shell=False)
except CalledProcessErrorWithStderr as e:
raw_output = e.output
error = e.error