May-04-2019, 09:31 AM
(This post was last modified: May-04-2019, 09:32 AM by Gribouillis.)
turtleman Wrote:What am I doing wrong?You're not doing anything wrong. It is the way python prints bytes objects
>>> x = b'foo bar' >>> print(x) b'foo bar'You can use the decode() method, without argument if the bytes string is encoded in utf8
>>> print(x.decode()) foo barStarting with python 3.7, an alternative is to use
text=True
in the call to subprocess.run(). Before that, you can use universal_newlines=True
. Then the output will be a str instance instead of a bytes. Starting with python 3.6, you can use encoding='utf8'
or another encoding value.output = subprocess.run(['dir'], stdout=subprocess.PIPE, text=True)also you don't need shell=True. Use a list as first argument of run().