1

Perl: attempting to access Expect object inside of Net::SSH::Expect gives an ERROR.

Example pseudo code:

my $m = Net::SSH::Expect->new(
        host        => 192.168.1.6,
        user        => 'root',
        password    => 'password',
        timeout     => 10,
        raw_pty     => 1,
        log_file    => '/tmp/net_ssh_expect_output.txt',
    );

$m->login();

$m->expect->log_file();

This throws the error: expect():

ERROR: if called directly (not as $obj->expect(...), but as Expect::expect(...), first parameter MUST be '-i' to set an object (list) for the patterns to work on. at (eval 99)[/usr/share/perl/5.18/perl5db.pl:732] line 2.

How should I be making the call to log_file() to grab the file handle and avoid that error message?

Here is the source code which is throwing the error: Expect.pm line 492.

I expect (heh heh) to get the file handle of the log file. It looks like I am calling it as $obj->expect(), but it throws that error. I'm probably missing something basic.

brian d foy
  • 129,424
  • 31
  • 207
  • 592
ZaPaDoS
  • 13
  • 4

1 Answers1

0

How should I be making the call to log_file() to grab the file handle and avoid that error message?

There is a specific method get_expect() that can be used to get the internal Expect object, you can use it like this:

my $logfile_handle = $m->get_expect()->log_file();
say {$logfile_handle} "Testing...";
Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174