[python] Return value of x = os.system(..)

When I type os.system("whoami") in Python, as root, it returns root, but when I try to assign it to a variable x = os.system("whoami") it set's the value of x to 0. Why ? (:

This question is related to python linux os.system

The answer is


os.system('command') returns a 16 bit number, which first 8 bits from left(lsb) talks about signal used by os to close the command, Next 8 bits talks about return code of command.

Refer my answer for more detail in What is the return value of os.system() in Python?