Skip to contentSkip to conversation

hcitool lescan scripting question...

DISCUSSION Urbani, Edmund 2 participants 2 messages Nov 11, 2014 – Nov 13, 2014 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

Hello,

now this may seem like a silly question, but I have been trying to do some simple shell scripting with hcitool's LE scan and redirected its out and err streams. The result is not quite what I am expecting:

hcitool lescan --duplicates > /tmp/lescan.out

This will create the output file immediately, but it remains empty until the hcitool process terminates. Only then does the entire output get flushed. Any idea why the output does not get written immediately? Ie. why I can't "tail -f /tmp/lescan.out"?

My intention was to pipe the output through a shell script to add a timestamp to each line, so I get a simple log during testing. I did not want to modify hcitool/write my own C program just for this purpose.

Kind regards,
Edmund

#1 lore raw

Hi Edmund,

Quoted 9 lines · Edmund

Hello,

now this may seem like a silly question, but I have been trying to do some simple shell scripting with hcitool's LE scan and redirected its out and err streams. The result is not quite what I am expecting:

hcitool lescan --duplicates > /tmp/lescan.out

Quoted 8 lines

This will create the output file immediately, but it remains empty until the hcitool process terminates. Only then does the entire output get flushed. Any idea why the output does not get written immediately? Ie. why I can't "tail -f /tmp/lescan.out"?

My intention was to pipe the output through a shell script to add a timestamp to each line, so I get a simple log during testing. I did not want to modify hcitool/write my own C program just for this purpose.

This is due to stdout buffering. Try with stdbuf:
stdbuf -oL hcitool lescan --duplicates > /tmp/lescan.out

Signature · 2 lines
Best regards, 
Szymon Janc