Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFE-3779 Show STDOUT/STDERR in case of command failure #26

Merged
merged 1 commit into from
Oct 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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