diff --git a/bactopia/utils.py b/bactopia/utils.py index 66daa53..ba6646f 100644 --- a/bactopia/utils.py +++ b/bactopia/utils.py @@ -1,4 +1,5 @@ import logging +import shlex import subprocess import sys from pathlib import Path @@ -33,7 +34,7 @@ def execute( logging.debug(f"Working directory: {directory}") try: command = subprocess.run( - cmd.split(" "), # Replace with your command and arguments + shlex.split(cmd), # Replace with your command and arguments cwd=directory, capture_output=True, text=True, # Decodes stdout/stderr as strings using default encoding @@ -49,15 +50,18 @@ def execute( return command.returncode except subprocess.CalledProcessError as e: if allow_fail: - logging.debug(f'"{cmd}" return exit code {e.returncode}') - logging.debug(e) + logger = logging.debug + else: + logger = logging.error + logger(f"STDOUT: \n{e.stdout}") + logger(f"STDERR:\n{e.stderr}") + logger(f'"{cmd}" return exit code {e.returncode}') + logger(e) + if allow_fail: return None else: - logging.error(f'"{cmd}" return exit code {e.returncode}') - logging.error(e) sys.exit(e.returncode) - def pgzip(files: list, cpus: int) -> list: """ Parallel gzip a list of files