There's a software package out there called
expect. Its page on freshmeat.net can be found
here.
I have not used it, but from what I read, it's intended to automate tasks that involve user input (like automating ftp, passwd, et.c). It might take a while to learn, but it might prove useful. In fact, you may already have it on your machine.