from subprocess import Popen, PIPE

def shell(args, input=''):
    """ uses subprocess pipes to call out to the shell.
    args:  args to the command
    input:  stdin
    returns stdout, stderr
    """
p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate(input=input)
return stdout, stderr
Wrapping an interactive command line application in a python script