Fix shell command not working after new error reporting.

This commit is contained in:
Darko Poljak 2016-07-12 20:15:08 +02:00
parent 001232f0d7
commit e2bb629535
2 changed files with 15 additions and 7 deletions

View File

@ -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:

View File

@ -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