in reply to interactively catching STDOUT/STDERR messages
If you're looking for Expect like behaviour, have you tried the Expect module? It may already do exactly what you want, exactly the way you're thinking of the problem.