Skip to content

Commit

Permalink
Merge branch 'topic/okurth/script-output-realtime' into 'master'
Browse files Browse the repository at this point in the history
output stdout/stderr from scripts immediately instead of after scripts are done

See merge request core-build/photon-os-installer!96
  • Loading branch information
Oliver Kurth committed Oct 30, 2024
2 parents e0a991d + 67d9d89 commit 66fd1a8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions photon_installer/commandutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,27 @@ 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]
for line in out.split("\0")
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):
Expand Down

0 comments on commit 66fd1a8

Please sign in to comment.