Exit grep hcitool lescan

How do I make grep output "hcitool lescan" or, if you like, connect it to anything. It seems that when I push something from "hcitool lescan", I do not get a way out.

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 
+6
source share
2 answers

The problem is stdout buffering. "hcitool lescan" does not output its output after every new device found, it just prints it with "\ n" (at least in the blue 5.27 sources that I am viewing). By default, if stdout is a terminal, then a “buffering string” is automatically set for buffering, otherwise it is configured to buffer (see here for a full description). Therefore, when you redirect hcitool output to grep, for example, it is buffered. If you wait long enough, you will see the expected grep result. To overcome this, you can use stdbuf to run hcitool with string buffering stdout:

$ stdbuf -oL hcitool lescan | grep B

+4
source

make sure you use sudo :

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

All Articles