From e2bb6295359a38bbf4bc856065649aae332191dc Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Tue, 12 Jul 2016 20:15:08 +0200 Subject: [PATCH] Fix shell command not working after new error reporting. --- cdist/exec/local.py | 19 +++++++++++++------ cdist/shell.py | 3 ++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/cdist/exec/local.py b/cdist/exec/local.py index bde2ceba..e2d07e8d 100644 --- a/cdist/exec/local.py +++ b/cdist/exec/local.py @@ -194,7 +194,8 @@ class Local(object): self.log.debug("Local mkdir: %s", path) os.makedirs(path, exist_ok=True) - def run(self, command, env=None, return_output=False, message_prefix=None): + def run(self, command, env=None, return_output=False, message_prefix=None, + save_output=True): """Run the given command with the given environment. Return the output as a string. @@ -216,11 +217,17 @@ class Local(object): env.update(message.env) try: - output, errout = exec_util.call_get_output(command, env=env) - self.log.debug("Local stdout: {}".format(output)) - self.log.debug("Local stderr: {}".format(errout)) - if return_output: - return output.decode() + if save_output: + output, errout = exec_util.call_get_output(command, env=env) + self.log.debug("Local stdout: {}".format(output)) + self.log.debug("Local stderr: {}".format(errout)) + if return_output: + return output.decode() + else: + # In some cases no output is saved. + # This is used for shell command, stdout and stderr + # must not be catched. + subprocess.check_call(command, env=env) except subprocess.CalledProcessError as e: exec_util.handle_called_process_error(e, command) except OSError as error: diff --git a/cdist/shell.py b/cdist/shell.py index 60faa2f8..dacff674 100644 --- a/cdist/shell.py +++ b/cdist/shell.py @@ -73,7 +73,8 @@ class Shell(object): self._init_environment() log.info("Starting shell...") - self.local.run([self.shell], self.env) + # save_output=False -> do not catch stdout and stderr + self.local.run([self.shell], self.env, save_output=False) log.info("Finished shell.") @classmethod