2020-02-08 13:39:35 +01:00
|
|
|
import shlex
|
|
|
|
import subprocess
|
|
|
|
import logging
|
|
|
|
|
2020-02-23 13:44:49 +01:00
|
|
|
def execute(cmd, wait=True, ignore_errors=False):
|
2020-02-08 13:39:35 +01:00
|
|
|
args = shlex.split(cmd)
|
|
|
|
logging.debug(cmd)
|
|
|
|
try:
|
|
|
|
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
|
except FileNotFoundError as e:
|
|
|
|
raise RuntimeError('{} not found'.format(cmd))
|
|
|
|
|
|
|
|
if wait:
|
|
|
|
out, _ = proc.communicate()
|
2020-02-23 13:44:49 +01:00
|
|
|
if proc.returncode != 0 and not ignore_errors:
|
2020-02-08 13:39:35 +01:00
|
|
|
raise RuntimeError('{} exited with {}'.format(cmd, proc.returncode))
|
|
|
|
return out.decode('utf-8')
|
|
|
|
return ''
|
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|