You need the pexpect module. http://www.noah.org/wiki/Pexpect