What is the return value of os.system() in Python?

Viewed 208936

I came across this:

>>> import os
>>> os.system('ls')
file.txt README
0

What is return value of os.system()? Why I get 0?

5 Answers

You might want to use

return_value = os.popen('ls').read()

instead. os.system only returns the error value.

The os.popen is a neater wrapper for subprocess.Popen function as is seen within the python source code.

Related