Net::Telnet $prematch, $match

Net::Telnet $prematch, $match

am 12.04.2007 16:18:07 von ton de w

Hello,
I am looking at a code fragment that I dont understand properly.
...
my ($prematch, $match) = $telnet->waitfor('/login: $i);
$telnet->print($user);
if (($prematch, $match) =$telnet->waitfor(string=> 'Choose a new
password'))
{
crash out - cannot go on
}
my ( $prematch, $match) = $telnet->waitfor('/password: $/i);
my($prematch, $match) = $telnet->print($password);
....

So what I do understand is line1 we wait for "login: " case
insensitive.
Then line2 supply the user - ($prematch, $match) not used at this
point.
line 3 - i am not really sure - $prematch contains the match up to
expression and $match the match expression but what is the if
statement comparing?
And how if we dont get the 'Choose new password' do we continue to
provide the password?

Actually I need to extend this program to do very similar things - is
there an alternative way of doing this?

TIA

Ton

Re: Net::Telnet $prematch, $match

am 12.04.2007 21:16:26 von Jim Gibson

In article <1176387487.128680.166810@b75g2000hsg.googlegroups.com>, ton
de w wrote:

> Hello,
> I am looking at a code fragment that I dont understand properly.
> ..
> my ($prematch, $match) = $telnet->waitfor('/login: $i);

I think you need '/login: $/i' there.

> $telnet->print($user);
> if (($prematch, $match) =$telnet->waitfor(string=> 'Choose a new
> password'))
> {
> crash out - cannot go on
> }
> my ( $prematch, $match) = $telnet->waitfor('/password: $/i);
> my($prematch, $match) = $telnet->print($password);
> ...
>
> So what I do understand is line1 we wait for "login: " case
> insensitive.
> Then line2 supply the user - ($prematch, $match) not used at this
> point.
> line 3 - i am not really sure - $prematch contains the match up to
> expression and $match the match expression but what is the if
> statement comparing?
> And how if we dont get the 'Choose new password' do we continue to
> provide the password?

My guess: check for a Timeout parameter in the call to new(). Also
check for a Errmode parameter or a call to errmode. My guess is that
your call to waitfor(string=>'Choose ...') is timing out and proceeding
to the next call (waitfor('/password: $/i');)

Note: it helps if you post a complete, minimal program so we don't have
to guess at what is going on.

>
> Actually I need to extend this program to do very similar things - is
> there an alternative way of doing this?

There is the Expect program:



or the Perl Expect.pm module:
.

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Re: Net::Telnet $prematch, $match

am 12.04.2007 22:11:15 von paduille.4061.mumia.w+nospam

On 04/12/2007 09:18 AM, ton de w wrote:
> Hello,
> I am looking at a code fragment that I dont understand properly.
> ...
> my ($prematch, $match) = $telnet->waitfor('/login: $i);
> $telnet->print($user);
> if (($prematch, $match) =$telnet->waitfor(string=> 'Choose a new
> password'))
> {
> crash out - cannot go on
> }

I'm assuming that the "errmode" is "return." When the second
$telnet->waitfor() succeeds, the method will return a list containing
values for $prematch and $match. If that happens, it means that the host
is demanding a new password, and since the script can't handle that, it
exits. The "if" statement tests whether a non-empty list was returned by
$telnet->waitfor().


> [...]