in reply to running R from perl

Expect performs such black magic. If you are running on Unix/Linux, this is exactly what you want. If you open the Expect.pm POD (via my link), and search for "How to automate login" you will see a top-to-bottom example of Expect looking for patterns and responding to them using anonymous subroutine handlers. Very cool.