in reply to Automate an SQL tool

Thats what Expect is for. Or Expect::Simple at your option.
Boris