in reply to Automating CPAN Configuration

Have you considered using expect? Here is a sample expect script that will spawn the CPAN shell, answer "no" if appropriate during the configuration prompt, and quit when it sees the normal cpan> prompt. If the manual config prompt doesn't appear, the script will still catch it. This was written in the previous few minutes, so it can really be cleaned up and set to do something other than smartass remarks when something goes wrong; however it seems to do the job:
# 10 second time limit for one of our conditions to be met set timeout 10 eval spawn "/usr/bin/perl" "-MCPAN -e shell" expect { "Are you ready for manual configuration?" { send "no\r" } "cpan>" { send "quit\r" expect eof exit } timeout { puts "\nWe ran out of time\n" exit } eof { puts "\nOh noes, unexpected EOF\n" exit } } # This will only be reached if a default configuration keypress was re +quired expect "cpan>" send "quit\r"

Replies are listed 'Best First'.
Re^2: Automating CPAN Configuration
by dsheroh (Monsignor) on May 11, 2006 at 15:10 UTC
    I hadn't thought of using the expect command itself, although Expect.pm did come to mind a couple hours after posting my question. I suppose that's the most sensible way of handling this, given that the code to actually do the remote module installs is Expect.pm-based, but I was still hoping to find something more streamlined even after I thought of it. (I'm... less than fond of Expect, as it seems to enforce a style of coding that feels ugly and cumbersome to me. But I can't think of any model that suits my taste better without giving up a lot of the flexibility and power of expect, so I guess I can't complain all that much about it.)

    So I guess I'm off to roll this into the existing code. Thanks for the suggestions, everyone!