Add execute_live function

The function will execute a command and print the output to the console
while the command is still running
This commit is contained in:
bom 2022-12-29 11:05:15 +01:00
parent b24332ebc0
commit d243c9d717

View file

@ -1,4 +1,4 @@
from subprocess import check_output from subprocess import check_output, Popen, PIPE
import sys import sys
def execute(cmd, shell=False): def execute(cmd, shell=False):
@ -8,5 +8,12 @@ def execute(cmd, shell=False):
output = check_output(cmd, shell=shell) output = check_output(cmd, shell=shell)
return output.rstrip() 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): def filter_none(list):
return [x for x in list if x is not None] return [x for x in list if x is not None]