You can use the expect tool.