2014-11-11 11:11:02

by Urbani, Edmund

[permalink] [raw]
Subject: hcitool lescan scripting question...


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


2014-11-13 16:56:21

by Szymon Janc

[permalink] [raw]
Subject: Re: hcitool lescan scripting question...

Hi Edmund,

On Tuesday 11 of November 2014 12:11:02 Urbani, Edmund wrote:
>
> 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.

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

--
Best regards,
Szymon Janc