From 0486853d7e847e551af0e5fd87f29a31ac20f597 Mon Sep 17 00:00:00 2001 From: Jonatan Schlag Date: Sat, 21 Apr 2018 13:23:47 +0200 Subject: [PATCH] Return exit code of executed commands Signed-off-by: Jonatan Schlag --- test.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test.py b/test.py index 54d256d..d5be079 100755 --- a/test.py +++ b/test.py @@ -355,7 +355,7 @@ class connection(): self.con.flush() def command(self, command): - self.write("{}\n".format(command)) + self.write("{}; echo \"END: $?\"\n".format(command)) # We need to read out the prompt for this command first # If we do not do this we will break the loop immediately @@ -367,6 +367,13 @@ class connection(): data = self.readline() self.log_console_line(data.decode()) + # We saved our exit code in data (the last line) + self.log.debug(data.decode()) + data = data.decode().replace("END: ", "") + self.log.debug(data) + self.log.debug(data.strip()) + return data.strip() + # A class which define and undefine a virtual network based on an xml file class network(): -- 2.39.2