From 64261a65cb8c4c7daeb35186f16d246d3211fa0a Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Tue, 24 Nov 2015 12:50:02 +0000 Subject: [PATCH] adb_shell: fixing handling of line breaks at the end of the output - adb protcol uses "\r\n" for line breaks. This is not handled by Python's line break translation, as not a file. So spliting on '\n' when extracting the exit code resulted in stray '\r' in the output. - adb_shell expects exit code to be echoed on the same line. This may not have been the case if latest output from executed command was not a complete line. An extra echo will now ensure that the exit code will be on its own line even in that case. --- devlib/utils/android.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/devlib/utils/android.py b/devlib/utils/android.py index 6f0330d..37e2680 100644 --- a/devlib/utils/android.py +++ b/devlib/utils/android.py @@ -293,14 +293,14 @@ def adb_shell(device, command, timeout=None, check_exit_code=False, as_root=Fals escape_double_quotes(command)) logger.debug(full_command) if check_exit_code: - actual_command = "adb{} shell '({}); echo $?'".format(device_string, - escape_single_quotes(command)) + actual_command = "adb{} shell '({}); echo; echo $?'".format(device_string, + escape_single_quotes(command)) raw_output, error = check_output(actual_command, timeout, shell=True) if raw_output: try: - output, exit_code, _ = raw_output.rsplit('\n', 2) + output, exit_code, _ = raw_output.rsplit('\r\n', 2) except ValueError: - exit_code, _ = raw_output.rsplit('\n', 1) + exit_code, _ = raw_output.rsplit('\r\n', 1) output = '' else: # raw_output is empty exit_code = '969696' # just because