英文:
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...";
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论