使用hcitool扫描蓝牙低功耗?

ahm*_*man 3 linux shell ubuntu bluetooth bluetooth-lowenergy

当我运行此命令时,ble设备仅扫描5秒钟:

$ sudo timeout 5s hcitool -i hci0 lescan
Run Code Online (Sandbox Code Playgroud)

输出显示在终端屏幕中.

但是当我将输出重定向到文件以保存广告设备的地址时,每次运行该命令时,我发现文件为空,输出在终端或文件中都不可见.

我用的命令:

$ sudo timeout 5s hcitool -i hci0 lescan > file.txt
Run Code Online (Sandbox Code Playgroud)

为了hcitool正确地将其输出重定向到文件,我该怎么办?

kay*_*lum 7

timeout默认情况下,将SIGTERM发送给程序.看起来hcitool不优雅地处理.而是使用SIGINT(相当于ctrl-c).

sudo timeout -s SIGINT 5s hcitool -i hci0 lescan > file.txt