Perhaps consider expect. The Wikipedia page also lists some alternatives. https://en.wikipedia.org/wiki/Expect