pexpect

Pexpect allows easy control of interactive console applications.

Here are some articles that you may find helpful