import subprocess as sp import logging def run(command, case, alias=None): if alias == None: alias = command log = logging.getLogger(alias) proc = sp.Popen( command, cwd=case, stdout=sp.PIPE, stderr=sp.PIPE, text=True, ) for line in proc.stdout: log.info(line[:-1]) for line in proc.stderr: log.info(line[:-1]) return proc.wait()