From 2e0219cac0b94a996c04a1017eb05256ae0e52bb Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Sat, 28 Jan 2023 08:26:29 -0800 Subject: [PATCH] fixing bash util (#779) --- langchain/utilities/bash.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/langchain/utilities/bash.py b/langchain/utilities/bash.py index 6872430a..50bd688c 100644 --- a/langchain/utilities/bash.py +++ b/langchain/utilities/bash.py @@ -12,15 +12,13 @@ class BashProcess: def run(self, commands: Union[str, List[str]]) -> str: """Run commands and return final output.""" - outputs = [] if isinstance(commands, str): commands = [commands] - for command in commands: - try: - output = subprocess.check_output(command, shell=True).decode() - if self.strip_newlines: - output = output.strip() - outputs.append(output) - except subprocess.CalledProcessError as error: - return str(error) - return outputs[-1] + commands = ";".join(commands) + try: + output = subprocess.check_output(commands, shell=True).decode() + except subprocess.CalledProcessError as error: + return str(error) + if self.strip_newlines: + output = output.strip() + return output