From a06016a4428b41a59133bcfbd6dcae5360a444f7 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Tue, 24 Nov 2015 15:49:38 +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. --- wlauto/utils/android.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wlauto/utils/android.py b/wlauto/utils/android.py index a898e7f7..ec7abd81 100644 --- a/wlauto/utils/android.py +++ b/wlauto/utils/android.py @@ -239,13 +239,13 @@ def adb_shell(device, command, timeout=None, check_exit_code=False, as_root=Fals full_command = 'adb {} shell "{}"'.format(device_string, 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