From d243c9d717344e6146c511105862c096f241d2c4 Mon Sep 17 00:00:00 2001 From: bom Date: Thu, 29 Dec 2022 11:05:15 +0100 Subject: [PATCH] Add execute_live function The function will execute a command and print the output to the console while the command is still running --- src/main/python/ddadevops/python_util.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/python/ddadevops/python_util.py b/src/main/python/ddadevops/python_util.py index 0ad4689..fef4ee0 100644 --- a/src/main/python/ddadevops/python_util.py +++ b/src/main/python/ddadevops/python_util.py @@ -1,4 +1,4 @@ -from subprocess import check_output +from subprocess import check_output, Popen, PIPE import sys def execute(cmd, shell=False): @@ -8,5 +8,12 @@ def execute(cmd, shell=False): output = check_output(cmd, shell=shell) return output.rstrip() +def execute_live(cmd): + p = Popen(cmd, stdout=PIPE) + for line in iter(p.stdout.readline, b''): + print(line.decode('utf-8'), end='') + p.stdout.close() + p.wait() + def filter_none(list): return [x for x in list if x is not None]