Capturing stdout from the shell in python 2.6

There is a handy subprocess.check_call function in 2.7, but if you’re using 2.6, you can use this (for some reason, it’s quite hard to find):

command = ‘ls -la’
stdout_handle = os.popen(command)
stdout =
print stdout

Leave a Reply

Your email address will not be published. Required fields are marked *