in reply to Connection to devices and command execution
Perhaps the Expect series of modules might be of use. There are also PTY handlers, and others that fall into the same problem space.
--MidLifeXis