Input to process using Python
Question: I have a command (Say foo) that I normally run from terminal like so:

    
    
        user@computer$ foo
        enter the string: *(here I enter some string)*
        RESULT OF THE COMMAND WITH THE GIVEN INPUT
    

I know beforehand what input I need to give. So, how do I automate the call
using this python code:

    
    
       from subprocess import call
       call(['foo'])
    

How do I automate the input to foo ?


Answer: You can check out the third-party [pexpect](http://www.noah.org/wiki/pexpect)
module ([Here is the API](http://pexpect.sourceforge.net/pexpect.html)):

    
    
    import pexpect
    child = pexpect.spawn('foo')
    child.expect('enter the string:')
    child.sendline('STRING YOU KNOW TO ENTER')
    child.close() # End Communication
    

