shell - how to properly read from stream in bash -


i reading shared memory stream producing infinite information output such as:

0x1 (timestamp) 12bytes:11216 +     1771/(47999+1) (0.036896) delta= 0+    1536/(47999+1) (0.032000) 11216.013361 23.534ms 2015.06.25 11:51:16.525 0x4 (referencetime) 12bytes:11215 + 24786286/(26999999+1) (0.918011) delta= 0+  806359/(26999999+1) (0.029856) 11216.013376 -95.366ms 2015.06.25 11:51:16.525 0x6 (processdelay) 4bytes: 32 (0x20) 0x7 (clockaccuracy) 8bytes: offset=0.000ppm (+-0.000ppm) 0xb (clockid) 8bytes: 01 00 00 00 42 22 01 00 0x20001 (samplerate) 4bytes: 48000 (0xbb80) 0x20002 (channels) 4bytes: 6 (0x6) 0x20003 (pcmlevel) 24bytes: -11041 -11541 -49076 -86121 -24846 -24382 0x20004 (pcmpeak) 24bytes: -8088 -8697 -37244 -84288 -21437 -21769 0x2000e (dolbydpmetadata) 39352bytes: linear time: 11216 +     1771/(47999+1) (0.036896) delta= 0+    1536/(47999+1) (0.032000) 

if try read stream following command:

while read line;       echo "$line";     echo "im here!" done < <(../tools/spucat adec-68) 

wherespucat cpp binary exacutable continuosly print out on console using printf() information incoming data packets.

this result:

im here! �k�g��e�x����b��h�������c����2��/n��-�u���qe�l�x���c�������������������������������x��4����o��m�����/��(������������������~��e�*�������; im here! ������r��$�|��j�n�p�4� 

if start script whit command:

while read line;       echo "$line";     echo "im here!" done < $(../tools/spucat adec-68) 

it never go inside while loop, start print out stream whaiting end. tehere way read line line , process inside while loop?

first, second loop won't work @ because attempting redirect result of command substitution - string - stdin. check simple example:

while read line ; echo "$line"; done < $(ls -l) 

which gives:

bash: $(ls): ambiguous redirect 

you need use process substitution:

< <(../tools/spucat adec-68) 

or called here string:

<<<$(../tools/spucat adec-68) 

another thing. if read arbitrary binary data suggest use -r option of read. prevents backslash being interpreted escape character. i'm not sure if entire solution of problem here, -r should used.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -