From fa3530c7e896ef8f2dcffe47922793ec7edbeaab Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sun, 8 Aug 2010 15:08:36 +0200 Subject: [PATCH] [molecule.utils] add exec_cmd_get_status_output function --- molecule/utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/molecule/utils.py b/molecule/utils.py index cb216fc..91e7f4f 100644 --- a/molecule/utils.py +++ b/molecule/utils.py @@ -73,6 +73,17 @@ def exec_cmd(args): # wildcards automatically ==> rsync no workie return subprocess.call(' '.join(args), shell = True) +def exec_cmd_get_status_output(args): + """Return (status, output) of executing cmd in a shell.""" + pipe = os.popen('{ ' + ' '.join(args) + '; } 2>&1', 'r') + text = pipe.read() + sts = pipe.close() + if sts is None: + sts = 0 + if text[-1:] == '\n': + text = text[:-1] + return sts, text + def exec_chroot_cmd(args, chroot, pre_chroot = None): """ Execute a command inside a chroot.