Skip to content

Commit

Permalink
Show STDOUT/STDERR in case of command failure
Browse files Browse the repository at this point in the history
Should help for autoconf not installed for masterfiles module
as well as any other commands which fail.

Ticket: CFE-3779
Changelog: title
  • Loading branch information
craigcomstock committed Oct 11, 2021
1 parent 4cceb25 commit 4b71106
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cfbs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import json
import copy
import subprocess
from collections import OrderedDict
from shutil import rmtree
from cf_remote.paths import cfengine_dir
Expand All @@ -13,16 +14,17 @@

def _sh(cmd: str):
# print(cmd)
r = os.system(cmd)
if r != 0:
user_error(f"Command failed - {cmd}")
try:
r = subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
user_error(f"Command failed - {cmd}\n{e.stdout.decode('utf-8')}")


def sh(cmd: str, directory=None):
if directory:
_sh(f"( cd {directory} && {cmd} ) 1>/dev/null 2>/dev/null")
_sh(f"cd {directory} && {cmd}")
return
_sh(f"( {cmd} ) 1>/dev/null 2>/dev/null")
_sh(f"{cmd}")


def mkdir(path: str):
Expand Down

0 comments on commit 4b71106

Please sign in to comment.