Skip to content

Commit df9aea8

Browse files
committed
Simplify command output capture
A pair of "surrogateescape" decode and encode was used to get from byte to bytes, with an internal utf-8 representation. (read more about surrogateescape in https://peps.python.org/pep-0383/) However the utf-8 representation was not used at all. Although this simplification is not strictly necessary (the results before and after must be the same) it took some time reading it and understanding how the encoding works during handling a problem that manifested in a failed command run (#356)
1 parent ab97550 commit df9aea8

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

unblob/extractors/command.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,14 @@ def extract(self, inpath: Path, outdir: Path):
2323
try:
2424
res = subprocess.run(
2525
cmd,
26-
encoding="utf-8",
27-
errors="surrogateescape",
2826
stdout=subprocess.PIPE,
2927
stderr=subprocess.PIPE,
3028
)
3129
if res.returncode != 0:
32-
stdout = res.stdout.encode("utf-8", errors="surrogateescape")
33-
stderr = res.stderr.encode("utf-8", errors="surrogateescape")
34-
3530
error_report = ExtractCommandFailedReport(
3631
command=command,
37-
stdout=stdout,
38-
stderr=stderr,
32+
stdout=res.stdout,
33+
stderr=res.stderr,
3934
exit_code=res.returncode,
4035
)
4136

0 commit comments

Comments
 (0)