【问题标题】:Grep hcitool lescan outputgrep hcitool lescan 输出
【发布时间】:2016-06-24 00:56:40
【问题描述】:

我如何 grep 'hcitool lescan' 的输出,或者将它通过管道传输到任何东西。似乎当我从“hcitool lescan”管道传输任何内容时,我没有得到任何输出。

root@edison:/mnt/rtd# hcitool lescan |grep B

^Croot@edison:/mnt/rtd# hcitool lescan | tee foo

^Croot@edison:/mnt/rtd# hcitool lescan
LE Scan ...
B0:B4:48:xx:xx:xx (unknown)
B0:B4:48:xx:xx:xx xxxxxxxx
B0:B4:48:yy:yy:yy (unknown)
B0:B4:48:yy:yy:yy yyyyyyyy

【问题讨论】:

    标签: pipe bluetooth-lowenergy bluez intel-edison hci


    【解决方案1】:

    问题在于标准输出缓冲。 'hcitool lescan' 不会在每个新找到的设备后刷新其输出,它只是用 '\n' 打印它们(至少在我正在查看的 bluez 5.27 源中)。默认情况下,如果 stdout 是终端,则缓冲自动设置为“行缓冲”,否则设置为缓冲(完整说明请参见 here)。 因此,例如,当您将 hcitool 的输出重定向到 grep 时,它会被缓冲。如果您等待的时间足够长,您会看到 grep 的预期输出。 为了克服这个问题,您可以使用 stdbuf 来运行带有 stdout 行缓冲的 hcitool:

    $stdbuf -oL hcitool lescan | grep B

    【讨论】:

    • 不幸的是,我似乎没有关于 intel edision/yocto coreutilities 的 stdbuf,也没有弄清楚在哪里可以找到它们。
    【解决方案2】:

    确保使用sudo运行:

    $ sudo stdbuf -oL hcitool lescan | grep <pattern>
    

    【讨论】:

    • 与 OP 的问题无关,但我发现安装 moreutils 包并使用 ts 命令为每个条目添加时间戳很有用:sudo stdbuf -oL hcitool lescan --duplicates | ts | grep &lt;pattern&gt;
    猜你喜欢
    • 1970-01-01
    • 2014-03-30
    • 2017-04-17
    • 2015-01-08
    • 2021-03-26
    • 2021-08-31
    • 2014-09-11
    • 2016-08-05
    • 2016-07-15
    相关资源
    最近更新 更多