加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

评估perl中的期望

发布时间:2020-12-16 06:16:20 所属栏目:大数据 来源:网络整理
导读:我在perl中使用Expect来连接远程机器并执行某些功能.示例代码就像 $outfile="ls -lrt";$outfile1="output";$exp-expect(30,-re,".*bash-.*" = sub{$exp-send("$outfile2 $outfile r")});$exp-expect(60,".*bash-.*" = sub{$exp-send("$shayam $Ram r")});
我在perl中使用Expect来连接远程机器并执行某些功能.示例代码就像

$outfile="ls -lrt";
$outfile1="output";

$exp->expect(30,-re,".*bash-.*" => sub{$exp->send("$outfile2 >$outfile r")});
$exp->expect(60,".*bash-.*" => sub{$exp->send("$shayam > $Ram r")});

即使第一个表达式失败,它也会等待60秒并执行第二个语句.我只是想检查一下,如果只有第一个语句通过它就应该继续.

解决方法

我猜你正在使用 the Expect.pm module documented here.如上所述:

If called in an array context expect()
will return
($matched_pattern_position,$error,
$successfully_matching_string,
$before_match,and $after_match).

因此,您可能希望在数组上下文中调用它,以便在正则表达式失败和发送失败时都可以获得错误.

my ($matched_pattern_position,$successfully_matching_string,$before_match,$after_match) =
  $exp->expect(30,".*bash-.*" =>
    sub{$exp->send("$outfile2 >$outfile r")}
);

$exp->expect(60,".*bash-.*" =>
    sub{$exp->send("$shayam > $Ram r")}
) if !defined $error;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读