From 6db1fddab906d0429a08efe410235f890d72eff1 Mon Sep 17 00:00:00 2001 From: Anushree Mathur Date: Thu, 28 Nov 2024 17:42:12 +0530 Subject: [PATCH] Removing the escape sequence from the console output! The output coming from the console Terminal consists of Bracketed Paste escape sequence! I have updated the code in a way that it will check the status output and see if the output has this sequence, it will remove this from the output and then use only integer o/p of status command! Before applying the patch status output was: ^[[?2004l0 After applying the patch status output is: 0 Signed-off-by: Anushree Mathur --- aexpect/client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aexpect/client.py b/aexpect/client.py index 522ece1..e0460f4 100644 --- a/aexpect/client.py +++ b/aexpect/client.py @@ -1311,11 +1311,13 @@ def cmd_status_output(self, cmd, timeout=60, internal_timeout=None, # Send the 'echo $?' (or equivalent) command to get the exit status status = self.cmd_output(self.status_test_command, 30, internal_timeout, print_func, safe) + # Removing the escape sequence from the status output + clean_status = astring.strip_console_codes(status) except ShellError as error: raise ShellStatusError(cmd, out) from error # Get the first line consisting of digits only - digit_lines = [_ for _ in status.splitlines() + digit_lines = [_ for _ in clean_status.splitlines() if self.__RE_STATUS.match(_.strip())] if digit_lines: return int(digit_lines[0].strip()), out