From 1e2ad5b77cf3407357b02c391143c8893c180e19 Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Mon, 24 Jul 2023 11:45:26 -0500 Subject: [PATCH] - Implemented workaround for python subprocess logging. --- dmrpp_generator/main.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/dmrpp_generator/main.py b/dmrpp_generator/main.py index 2c99fd4..c3af65a 100644 --- a/dmrpp_generator/main.py +++ b/dmrpp_generator/main.py @@ -46,6 +46,10 @@ def __init__(self, **kwargs): self.timeout = int(self.dmrpp_meta.get( 'get_dmrpp_timeout', os.getenv('GET_DMRPP_TIMEOUT', '60')) ) + self.enable_subprocess_logging = self.dmrpp_meta.get( + 'enable_subprocess_logging', os.getenv('ENABLE_SUBPROCESS_LOGGING', False) + ) + self.logger_to_cw.info(f'get_dmrpp_timeout: {self.timeout}') @property @@ -163,8 +167,15 @@ def add_missing_files(self, dmrpp_meta, file_name): def run_command(self, cmd): """ Run cmd as a system command """ - out = subprocess.run(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, - check=True, timeout=self.timeout) + stdout = None + stderr = None + + if self.enable_subprocess_logging: + stdout = subprocess.PIPE + stderr = subprocess.STDOUT + + out = subprocess.run(cmd.split(), stdout=stdout, stderr=stderr, timeout=self.timeout, check=True) + return out def dmrpp_generate(self, input_file, local=False, dmrpp_meta=None):