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

huangapple go评论55阅读模式
英文:

Attempting to access Expect object inside of Net::SSH::Expect gives an ERROR

问题

Perl:尝试在Net::SSH::Expect内部访问Expect对象会导致错误。

示例伪代码:

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();

这会引发错误:expect():

错误:如果直接调用(而不是作为$obj->expect(...),而是作为Expect::expect(...)),第一个参数必须为'-i',以设置一个对象(列表)以使模式生效。位于(eval 99)[/usr/share/perl/5.18/perl5db.pl:732]的第2行。

我应该如何调用log_file()来获取文件句柄并避免该错误消息?

这是引发错误的源代码:Expect.pm第492行

我期望(嘿嘿)获得日志文件的文件句柄。看起来我将其称为$obj->expect(),但它引发了该错误。我可能漏掉了一些基础的东西。

英文:

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.

答案1

得分: 0

如何调用log_file()以获取文件句柄并避免错误消息?
有一个特定的方法get_expect()可用于获取内部的Expect对象,您可以像这样使用它:

my $logfile_handle = $m->get_expect()->log_file();
say {$logfile_handle} "Testing...";
英文:

> 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...";

huangapple
  • 本文由 发表于 2023年4月11日 01:36:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75979341.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定