the documentation says that popen returns the error code, or 'None', of the shell process. this code however always returns '1' even though the command operates fine. f=os.popen("ls /dev/loop*") loopdevices = f.read() if not f.close() == 'None': #fails on <>0: also raise Exception, "couldn't find any loop devices."