linux - 使用 perl 和串行设备检测 Linux 启动

标签 linux perl automation serial-port boot

我正在编写一个启动 Linux 镜像的 Perl 脚本,并且需要检测该镜像是否到达登录提示符。我正在使用 Device::serial 模块与开发板进行通信。我在检测登录字符串时遇到问题。我认为这可能与 Linux 启动期间发生的大量打印有关。下面的代码 try catch 提示。奇怪的是,它仅在我添加不必要的“读取”命令时才起作用

# 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--;
}

“lookfor”对于 Linux 启动场景有好处吗?为什么“读取”会使这段代码起作用?

谢谢大家

最佳答案

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。我怀疑这会导致您的问题。还要注意超时。

关于linux - 使用 perl 和串行设备检测 Linux 启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10394247/

相关文章:

android - 使用 Espresso 自动化 Android APK

automation - GetAsTable 问题 - Intellibot RPA

linux - 当我尝试链接测试文件时出现文件错误

linux - 如何在 linux 主机上运行 windows docker 容器?

linux - 在 Linux 上的 docker 中重叠绑定(bind)挂载和权限

regex - 使用 Perl,如何使用每个数组元素内的数字值对数组进行排序?

python - 如何使用python关闭同一应用程序的两个窗口?

linux - UNIX Case 语句中的模式匹配

perl - readdir 以什么编码返回文件名?

perl - 如果间隔计时器事件始终准备就绪,为什么 AnyEvent::child 回调不会运行?