mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 10:10:46 +00:00
utils/android: Echo the exit code of the actual command
When executing a command using `su`, the `echo` command was returning the error code of the invocation of `su` rather than the command itself. Usually `su` should mimic the return code of the command it is executing however this is not always the case which can cause issues.
This commit is contained in:
parent
988de69b61
commit
964fde2fef
@ -438,6 +438,14 @@ def _ping(device):
|
|||||||
def adb_shell(device, command, timeout=None, check_exit_code=False,
|
def adb_shell(device, command, timeout=None, check_exit_code=False,
|
||||||
as_root=False, adb_server=None, su_cmd='su -c {}'): # NOQA
|
as_root=False, adb_server=None, su_cmd='su -c {}'): # NOQA
|
||||||
_check_env()
|
_check_env()
|
||||||
|
|
||||||
|
# On older combinations of ADB/Android versions, the adb host command always
|
||||||
|
# exits with 0 if it was able to run the command on the target, even if the
|
||||||
|
# command failed (https://code.google.com/p/android/issues/detail?id=3254).
|
||||||
|
# Homogenise this behaviour by running the command then echoing the exit
|
||||||
|
# code of the executed command itself.
|
||||||
|
command += r' ; echo "\n$?"'
|
||||||
|
|
||||||
parts = ['adb']
|
parts = ['adb']
|
||||||
if adb_server is not None:
|
if adb_server is not None:
|
||||||
parts += ['-H', adb_server]
|
parts += ['-H', adb_server]
|
||||||
@ -447,12 +455,6 @@ def adb_shell(device, command, timeout=None, check_exit_code=False,
|
|||||||
command if not as_root else su_cmd.format(quote(command))]
|
command if not as_root else su_cmd.format(quote(command))]
|
||||||
|
|
||||||
logger.debug(' '.join(quote(part) for part in parts))
|
logger.debug(' '.join(quote(part) for part in parts))
|
||||||
# On older combinations of ADB/Android versions, the adb host command always
|
|
||||||
# exits with 0 if it was able to run the command on the target, even if the
|
|
||||||
# command failed (https://code.google.com/p/android/issues/detail?id=3254).
|
|
||||||
# Homogenise this behaviour by running the command then echoing the exit
|
|
||||||
# code.
|
|
||||||
parts[-1] += ' ; echo "\n$?"'
|
|
||||||
try:
|
try:
|
||||||
raw_output, _ = check_output(parts, timeout, shell=False, combined_output=True)
|
raw_output, _ = check_output(parts, timeout, shell=False, combined_output=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user