Search code examples
pythonlinuxpython-os

What does os.system return and how can I convert its output?


I am new to the os library, and while experimenting with decoding QR codes and extracting only the meaningful part of the output, I received this error:

AttributeError: 'int' object has no attribute 'replace'

At first glance I thought that I should be casting the returned value of the os.system() function, but I received the same error again.

Here's my code:

import os
test = str(os.system("zbarimg *.png"))
test.replace("QR-Code:", "")
print(test)

Solution

  • You probably need subprocess.check_output() as it allows you to

    Run command with arguments and return its output as a byte string.