Return exit code of executed commands
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Sat, 21 Apr 2018 11:23:47 +0000 (13:23 +0200)
committerJonatan Schlag <jonatan.schlag@ipfire.org>
Sat, 21 Apr 2018 11:23:47 +0000 (13:23 +0200)
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
test.py

diff --git a/test.py b/test.py
index 54d256d..d5be079 100755 (executable)
--- 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():