Skip to content

Commit

Permalink
Merge pull request #26 from craigcomstock/CFE-3779
Browse files Browse the repository at this point in the history
CFE-3779 Show STDOUT/STDERR in case of command failure
  • Loading branch information
olehermanse authored Oct 12, 2021
2 parents 4cceb25 + e2ed14d commit a883a0d
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 a883a0d

Please sign in to comment.