免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1569 | 回复: 1
打印 上一主题 下一主题

TelNet.pm如何捕捉超时? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-05-16 21:27 |只看该作者 |倒序浏览
...
if(defined($net_telnet))
        {
        my $str = "\@output = \$net_telnet->;cmd(String =>; \$cmd,Output =>; \$output,Timeout =>; \$NetTimeout)";
                print "\$str = $str\n";
                eval($str);
...

前后都不用管它,关键是如果timeout的话,会打印
command timed-out at test.pl line 72,并直接退出程序,我希望捕捉到超时,可以作相应处理。请问如何捕捉呢?谢谢

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
2 [报告]
发表于 2005-05-17 08:23 |只看该作者

TelNet.pm如何捕捉超时?

http://search.cpan.org/~jrogers/Net-Telnet-3.03/lib/Net/Telnet.pm
errmode - define action to be performed on error

    $mode = $obj->;errmode;

    $prev = $obj->;errmode($mode);

    This method gets or sets the action used when errors are encountered using the object. The first calling sequence returns the current error mode. The second calling sequence sets it to $mode and returns the previous mode. Valid values for $mode are "die" (the default), "return", a coderef, or an arrayref.

    When mode is "die" and an error is encountered using the object, then an error message is printed to standard error and the program dies.

    When mode is "return" then the method generating the error places an error message in the object and returns an undefined value in a scalar context and an empty list in list context. The error message may be obtained using errmsg().

    When mode is a coderef, then when an error is encountered coderef is called with the error message as its first argument. Using this mode you may have your own subroutine handle errors. If coderef itself returns then the method generating the error returns undefined or an empty list depending on context.

    When mode is an arrayref, the first element of the array must be a coderef. Any elements that follow are the arguments to coderef. When an error is encountered, the coderef is called with its arguments. Using this mode you may have your own subroutine handle errors. If the coderef itself returns then the method generating the error returns undefined or an empty list depending on context.

    A warning is printed to STDERR when attempting to set this attribute to something that's not "die", "return", a coderef, or an arrayref whose first element isn't a coderef.

看仔細...你會找到你要的答案的..
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP