评估 Perl 中的 Expect
我正在 perl 中使用 Expect 连接到远程计算机并执行某些功能。示例代码就像
$outfile="ls -lrt";
$outfile1="output";
$exp->expect(30,-re,".*bash-.*" => sub{$exp->send("$outfile2 >$outfile \r")});
$exp->expect(60,-re,".*bash-.*" => sub{$exp->send("$shayam > $Ram \r")});
即使第一个表达式失败,它也会等待 60 秒并执行第二个语句。我只是想检查一下,如果只有第一个语句通过,它就应该继续。
I am using Expect in perl to connect to remote machine and execute certain functions. sample code is like
$outfile="ls -lrt";
$outfile1="output";
$exp->expect(30,-re,".*bash-.*" => sub{$exp->send("$outfile2 >$outfile \r")});
$exp->expect(60,-re,".*bash-.*" => sub{$exp->send("$shayam > $Ram \r")});
Even if the first expression fails it will wait for 60 sec and will execute the second statement. I just want to make a check that if only the first statement passes it should proceed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜您正在使用此处记录的 Expect.pm 模块 。正如那里所说:
因此,您可能希望在数组上下文中调用它,以便在正则表达式失败和发送失败时都会收到错误。
I am guessing you are using the Expect.pm module documented here. As stated there:
So you likely want to call it in array context so you can get an error, both if the regex fails and if the send fails.