免费注册 查看新帖 |

Chinaunix

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

如何得到telnet的超时信号 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-07-03 11:25 |只看该作者 |倒序浏览
代码片断:


  1.      #建立连接么,这步没问题
  2.      my $t = new Net::Telnet (Timeout => 400,
  3.                           Prompt => '/[\$%#>] $|[\$%#>]$/');
  4.      $t->open($config->{"middle_sum"}->{"server"});
  5.      $t->login($config->{"middle_sum"}->{"user"},$config->{"middle_sum"}->{"pass"});

  6.      #问题出在这个问题上了,这个命令调用执行起来比较慢的,导致超时
  7.      my @retu = $t->cmd($command);
  8.      &print_detail_log("Bridge tpd->tpc Return:@retu\n");

  9.      #将telnet过去执行程序的结果输出日志(成功就Success,失败就Fail,没什么好说的)
  10.      my $cmd_retu;
  11.      foreach my $line (@retu){
  12.               chomp($line);
  13.               if($line =~ /Error|rollback/){$cmd_retu = "Fail";last;}
  14.      }
  15.      if($cmd_retu eq ''){$cmd_retu = 'Success!'}
  16.      &printlog("Bridge tpd->tpc Return:$cmd_retu\n");
复制代码


程序环境:windows
telnet对象:UNIX

我现在想知道的是perl发现一个telnet过程超时的话会怎么做?
关掉程序进程是肯定的了,还会有其他内部操作么?
我如果想在超时之后程序中断之前,在日志中写入因超时而中断应该怎么样作?
UNIX会在telnet超时时弄个什么信号出来么?
还有windows没信号量,咋整?

当然把超时时间设的大一点可能会解决问题,但是我希望了解一些深入点的东西,请各位达人指点一二,多谢啦~~

论坛徽章:
0
2 [报告]
发表于 2007-07-03 17:40 |只看该作者
将errormode 设置成return
可以捕获错误

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