Hello fellow monks. I am hoping you can help me with an Expect question. I'll try to explain it as clearly and briefly as possible.

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.

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; } ], );
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:
SWF::File [requires] Readonly [requires] List::MoreUtils [requires] [[AUTO-ENTER]] [[AUTO-ENTER]] [[AUTO-ENTER]]
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.

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


In reply to Expect.pm and STDIN question by Archon810

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.