Use subprocess.run with encoding="utf-8"
hughdbrown opened this issue · 0 comments
hughdbrown commented
Lines 36 to 40 in 2f5a026
if you pass encoding='utf-8'
to subprocess.run
, your strings are automatically decoded:
>>> s = subprocess.run("/bin/echo 'hello'".split(" "), stdout=subprocess.PIPE)
>>> s.stdout
b"'hello'\n"
>>> s = subprocess.run("/bin/echo 'hello'".split(" "), stdout=subprocess.PIPE, encoding="utf-8")
>>> s.stdout
"'hello'\n"
So:
try:
result = subprocess.check_output(subprocess_args, stderr=subprocess.STDOUT, encoding="utf-8")
except subprocess.CalledProcessError as e:
return e.output, e.returncode
return result, 0