[modules/shell] Update to new API

This commit is contained in:
tobi-wan-kenobi 2020-03-30 21:09:09 +02:00
parent 251a23d2f1
commit 422a9986b4
2 changed files with 37 additions and 47 deletions

View file

@ -9,12 +9,15 @@ def execute(cmd, wait=True, ignore_errors=False):
try:
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
except FileNotFoundError as e:
raise RuntimeError('{} not found'.format(cmd))
raise RuntimeError('{} not found'.format(cmd))
if wait:
out, _ = proc.communicate()
if proc.returncode != 0 and not ignore_errors:
raise RuntimeError('{} exited with {}'.format(cmd, proc.returncode))
if proc.returncode != 0:
err = '{} exited with code {}'.format(cmd, proc.returncode)
if ignore_errors:
return err
raise RuntimeError(err)
return out.decode('utf-8')
return ''