From 67d9d89895169bc3f7c436a06d066eef18625c70 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Mon, 28 Oct 2024 20:55:06 +0000 Subject: [PATCH] output stdout/stder from scripts immediately instead after scripts are done --- photon_installer/commandutils.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/photon_installer/commandutils.py b/photon_installer/commandutils.py index bd5ca8e..a0e2f22 100644 --- a/photon_installer/commandutils.py +++ b/photon_installer/commandutils.py @@ -29,13 +29,16 @@ def run(self, cmd, update_env=False): use_shell = not isinstance(cmd, list) process = subprocess.Popen( cmd, shell=use_shell, text=True, - stdout=subprocess.PIPE, stderr=subprocess.PIPE + stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) - out, err = process.communicate() + out = "" + for line in process.stdout: + self.logger.info(line.rstrip()) + out += line + process.wait() + if out != "": - self.logger.info(out) if update_env: - os.environ.clear() os.environ.update( dict( line.partition("=")[::2] @@ -43,12 +46,10 @@ def run(self, cmd, update_env=False): if line ) ) - process.wait() retval = process.returncode if retval != 0: self.logger.info(f"Command failed: {cmd}") self.logger.info(f"Error code: {retval}") - self.logger.error(err) return retval def run_in_chroot(self, chroot_path, cmd, update_env=False):