Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Perl Expect Command output

by Khen1950fx (Canon)
on Aug 27, 2011 at 22:53 UTC ( #922845=note: print w/ replies, xml ) Need Help??


in reply to Perl Expect Command output

First, try running it in debug mode

#!/usr/bin/perl use strict; use warnings; use Expect; $Expect::Debug = 1; my $timeout = 10; ...
Expect the unexpected:).

Update: In case you're still stumped, I put help in a callback. Give this a try:

#!/usr/bin/perl -slw use strict; use Expect; use Data::Dumper::Concise; #$Expect::Debug = 1; my $timeout = 10; my $command = 'telnet'; my $params = '10.123.125.13'; my $exp = Expect->spawn($command, $params) or die "Cannot spawn sftp command"; $exp->expect($timeout, ['mpp>']); $exp->send('enable'); $exp->expect($timeout, ['mpp#']); $exp->send(&help); $exp->expect($timeout, ['mpp#']); $exp->send('exit'); $exp->send('logout'); $exp->soft_close(); sub help { print "help\n\n", "List of available commands\n", " The current commands are: \n", " enable\n", " help\n", " exit\n", " logout\n"; }


Comment on Re: Perl Expect Command output
Select or Download Code
Re^2: Perl Expect Command output
by armstd (Friar) on Aug 28, 2011 at 18:00 UTC

    They seem to be asking for the output from a command ('help' in this case) executed on the remote device. before is the way to do it. What debugging steps have you taken already and what did you get? Since you are not error checking your spawn, do you even know if you're successfully connecting?

    --Dave

      Thanks for the info. I had tried with a command which stores the buffer content of 'just before executed command'.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://922845]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (16)
As of 2014-09-30 16:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (378 votes), past polls