Skip to content

Commit

Permalink
Update run_logged_subprocess to return a tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Campbell committed Sep 17, 2020
1 parent 290ab8c commit 6a4c2b2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions utils/venv-manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_args() -> argparse.Namespace:
return parser.parse_args()


def run_logged_subprocess(command: Union[str, list], timeout: int = 10, shell: bool = False) -> list:
def run_logged_subprocess(command: Union[str, list], timeout: int = 10, shell: bool = True) -> tuple:
"""Executes a shell command using subprocess with logging.
stderr is redirected to stdout and stdout is pipped to logger.
Expand All @@ -78,18 +78,18 @@ def run_logged_subprocess(command: Union[str, list], timeout: int = 10, shell: b
Example:
Running a successful command:
run_logged_subprocess(command=["git", "commit", "-m", "'Commit message.'"])
Returns: {"returncode": 0, "output": []}
Returns: (0, "")
Running an unsuccessful shell command with a 20 second timeout:
run_logged_subprocess(command="cd test/", timeout=20, shell=True)
Returns: {"returncode": 1, "output": ["cd: test: No such file or directory"]}
Returns: (1, "cd: test: No such file or directory\n")
Args:
command (Union): The command to run. If shell=False, pass a list with the first item being the command and the subsequent items being arguments. If shell=True, pass a string as you would type it into a shell.
timeout (int): The number of seconds to wait for a program before killing it
Returns:
dict: Containing subprocess return code and output.
tuple: With the first value being the return code and second being the combined stdout+stderr
"""
logger.debug(f"Entering subprocess for '{command}'")
with subprocess.Popen(command,\
Expand All @@ -116,7 +116,7 @@ def run_logged_subprocess(command: Union[str, list], timeout: int = 10, shell: b
logger.debug(f"Subprocess for '{command}' completed successfuly")
finally:
logger.debug(f"Exiting subprocess for '{command}'")
return {"returncode": logged_shell_process.returncode, "output": process_output_lines}
return (logged_shell_process.returncode, process_output_stream)



Expand Down

0 comments on commit 6a4c2b2

Please sign in to comment.