Reference

Basic usage

import sys
import subprocess

def main():
    command = 'ls -la ./'
    pro = subprocess.Popen(command, shell=True)
    if pro.wait() != 0:
        print>>sys.stderr, 'Error!'
    else:
        print command, 'has succeeded'

if __name__ == '__main__':
    main()