Take the 2-minute tour ×  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)*  I know
beforehand what input I need to give. So, how do I automate the
call using this python code:     from subprocess import call
How do I automate the input to foo ?  share|improve this
question call([input('Enter the string')]) in Python 3.x, or
call([raw_input()]) for Python 2.x –  karthikr Oct 3 '13 at
18:44 this has no reference to foo. How do I call it? –  tdk Oct
3 '13 at 22:33 @user1928721 Don't use the method in the comment
above. It's not what you want. –  SethMMorton Oct 4 '13 at 1:30
add comment  2 Answers  You can check out the third-party
pexpect module (Here is the API):  import pexpect child =
pexpect.spawn('foo') child.expect('enter the string:')
child.sendline('STRING YOU KNOW TO ENTER') child.close() # End
Communication share|improve this answer add comment  Use Popen
and communicate:  from subprocess import Popen, PIP