Skip to content

Commit

Permalink
Properly capture STDERR from Podman
Browse files Browse the repository at this point in the history
  • Loading branch information
yaqwsx committed Nov 23, 2023
1 parent 5a50ee1 commit ba892d9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions surveyor/podman.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import json
import select
import time
import subprocess
import contextlib
Expand Down Expand Up @@ -174,13 +175,18 @@ def invokePodmanCommandPoll(command, output):
Invoke podman command and continuously output stdout and stderr via a callback
"""
command = podmanBaseCommand(command)
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in iter(p.stdout.readline, b''):
output(line.decode("utf-8"))
output(p.stdout.read().decode("utf-8"))
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

while True:
readable, _, _ = select.select([p.stdout, p.stderr], [], [], 0.1)
for file in readable:
line = file.readline().decode("utf-8")
output(line)
if p.poll() is not None:
break
exitcode = p.wait()
if exitcode != 0:
raise PodmanError(f"{' '.join(command)}", "")
raise RuntimeError(f"{' '.join(command)}", "")

def imageExists(name):
"""
Expand Down

0 comments on commit ba892d9

Please sign in to comment.