[molecule.utils] add exec_cmd_get_status_output function

This commit is contained in:
Fabio Erculiani
2010-08-08 15:08:36 +02:00
parent 3d5e7537c4
commit 6c7e08d3ec
+11
View File
@@ -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.