From bbd2f1c781c8791f1626e003f86ebaa89260c8f6 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Tue, 23 Mar 2021 15:51:36 +0900 Subject: base: add run2() to enable to get command return value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current run() can't handle command return value. This patch adds new run2() which can handle return value. Signed-off-by: Kuninori Morimoto Reviewed-by: Niklas Söderlund --- scripts/base.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/base.py b/scripts/base.py index 5e5161e..324298e 100755 --- a/scripts/base.py +++ b/scripts/base.py @@ -73,13 +73,18 @@ class base: # # run command and get result as plane text #-------------------- - def run(self, command): + def run2(self, command): # Ughhhh # I don't like python external command !! # (ノ `Д´)ノ go away !! - return self.chomp(subprocess.Popen(command, shell=True, stdout=subprocess.PIPE).\ - communicate()[0].decode("utf-8")); + child = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + stdout, stderr = child.communicate() + + return self.chomp(stdout.decode("utf-8")), child.returncode; + + def run(self, command): + return self.run2(command)[0] #-------------------- # run1() -- cgit v1.2.3