1

Why I get output with b and ''?

import subprocess

result = subprocess.run(['php', 'index.php'], stdout=subprocess.PIPE, check=True)
print(result.stdout) 

Output => b'Hello'

In Php I have just echo().

  • 1
    Possible duplicate of [What does a b prefix before a python string mean?](https://stackoverflow.com/questions/2592764/what-does-a-b-prefix-before-a-python-string-mean) – roganjosh May 09 '18 at 21:11

1 Answers1

0

result.stdout is a bytes object, and the bytes.__str__() methods returns its representation (see repr()).

Try with print(result.stdout.decode('utf-8')) to decode the bytes as UTF-8.

Suggested reading: Unicode HOWTO

fferri
  • 18,285
  • 5
  • 46
  • 95