Take a look to "expect" language. http://sourceforge.net/projects/expect/ This is a extension to tcl/tk and provide a lot of things which can perfectly be used to run automated tests or control (remote) scripts and applications.
The thing you do:
Write a script where you can do some actions like starting an application or a shell or run a batch. Then you have a loop which have pairs of expected inputs and actions which should be done if these inputs are catched. And there is also a timeout clause!
Expect itself runs on all platforms I know and the scripts are portable to all OS.
We use it to run telnet sessions, running apps and batches and monitor the reactions of the DUT via serial/usb/network links. It is very flexible and easy to use. We also use expect as master script for a lot of gtest based unit tests.