使用perl和串行设备检测Linux引导

时间:2012-05-01 06:14:54

标签: linux perl automation serial-port boot

我正在编写一个引导linux映像的perl脚本,需要检测映像是否到达登录提示符。我正在使用Device :: serial模块与开发板进行通信。我遇到检测登录字符串的问题。我认为这可能与Linux启动期间发生的大量打印有关。下面的代码尝试捕获提示。奇怪的是它只有在我添加了不必要的“读取”命令时才有效

# Wait for login prompt
$port->are_match("login:");
$gotit   = "";
$timeout = 60;
until (($gotit ne "") or ($timeout eq 0)) 
{
    $gotit = $port->lookfor;       # poll until data ready
    die "Aborted without match\n" unless (defined $gotit);
    $read = $port->read(1000000);
    $port->lookclear;
    sleep(1);
    $timeout--;
}

对于linux启动方案是否“很好”?为什么“阅读”使这段代码有效?

谢谢大家

1 个答案:

答案 0 :(得分:0)

CPAN doc page说要这样做:

  my $gotit = "";
  until ("" ne $gotit) {
      $gotit = $PortObj->lookfor;       # poll until data ready
      die "Aborted without match\n" unless (defined $gotit);
      sleep 1;                          # polling sample time
  }

在他们的循环中没有调用$port->lookClear。我怀疑这是导致你的问题。还要注意那个超时。