pipe - Grep Hcitool Lescan输出

标签 pipe bluetooth-lowenergy bluez intel-edison hci

我该如何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

最佳答案

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

$stdbuf -oL hcitool lescan | grep B

关于pipe - Grep Hcitool Lescan输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35895175/

相关文章:

bluetooth - 无法通过 DBus 在 Bluez 中设置 SSP 模式

linux - 在 linux 命令行中使用低功耗蓝牙

c - popen2() 如何在 c 中工作?

Android 蓝牙 LE MAC 地址随机化

ios - 核心蓝牙状态保存和恢复不工作,无法将应用程序重新启动到后台

javascript - 为什么我通过 BLE 向设备发送数据时看不到任何通知?

linux - 使用 Bluez/Linux,我可以运行广播 BLE ibeacons 的守护进程并同时使用 RFCOMM 进行连接吗?

python - 在 sys.stdin.read() 和子进程调用 vim 之后如何不弄乱终端?

kubernetes - 有没有一种方便的方法可以将多个 kubectl 命令通过管道传递给彼此?

Angular 日期管道自定义输出