Skip to content

Commit a9f986f

Browse files
use subprocess.check_output
1 parent 84cc298 commit a9f986f

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

codexctl/device.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -737,24 +737,20 @@ def install_sw_update(self, version_file: str, bootloader_files: dict[str, bytes
737737

738738
else:
739739
print("Running swupdate")
740-
command = f"/usr/sbin/swupdate-from-image-file {version_file}"
740+
command = ["/usr/sbin/swupdate-from-image-file", version_file]
741741
self.logger.debug(command)
742742

743-
with subprocess.Popen(
744-
command,
745-
text=True,
746-
shell=True,
747-
stdout=subprocess.PIPE,
748-
stderr=subprocess.PIPE,
749-
env={"PATH": "/bin:/usr/bin:/sbin:/usr/sbin"},
750-
) as process:
751-
if process.wait() != 0:
752-
print("".join(process.stderr.readlines()))
753-
raise SystemError("Update failed")
754-
755-
self.logger.debug(
756-
f"Stdout of swupdate: {''.join(process.stdout.readlines())}"
743+
try:
744+
output = subprocess.check_output(
745+
command,
746+
stderr=subprocess.STDOUT,
747+
text=True,
748+
env={"PATH": "/bin:/usr/bin:/sbin:/usr/sbin"},
757749
)
750+
self.logger.debug(f"Stdout of swupdate: {output}")
751+
except subprocess.CalledProcessError as e:
752+
print(e.output)
753+
raise SystemError("Update failed")
758754

759755
print("Update complete and device rebooting")
760756
os.system("reboot")

0 commit comments

Comments
 (0)