Archon810 has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to automate some cpan module installation, but it seems like cpan isn't allowing to auto-yes all inputs and I can't even disable the Is it OK to try to connect to the Internet [yes] prompt.
So, I wrote a little Expect script that would send "\n" to everything that matches [.*?]. Here it is, with a few random modules.
The only problem (and it's not really an issue but I'd like the script to be clean), is it triggers on things like this, that don't even have an STDIN prompt:use strict; use Expect; my $exp = Expect->spawn("cpan -i AMF::Perl Crypt::GeneratePassword Dat +e::Manip") or die "Cannot spawn ssh: $!\n"; $exp->expect( undef, [qr/\[.*?\]/ => sub { my $fh = shift; print "\n[[AUTO-ENTER]]\n"; $fh->send( "\n"); exp_continue; } ], );
I do not want to make a whitelist or a blacklist of things that should or should not trigger sending the "\n". Ideally, it would only send anything if the line is followed by an STDIN prompt.SWF::File [requires] Readonly [requires] List::MoreUtils [requires] [[AUTO-ENTER]] [[AUTO-ENTER]] [[AUTO-ENTER]]
So the question to you all, mighty monks, can one detect an STDIN prompt in Expect and only perform an action if it's there, for example on the same line as the text being regexed?
Please let me know if I'm not being clear enough.
Thanks!
Artem
http://beerpla.net
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Expect.pm and STDIN question
by salva (Canon) on Jan 07, 2009 at 21:39 UTC | |
by Archon810 (Initiate) on Jan 07, 2009 at 22:26 UTC |