我正在编写一个启动 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/