views:

142

answers:

3

I want to use zbarcam but after reading a barcode, it doesn't stop.

$ zbarcam | xvkbd -file - -window emacs
EAN-13:6941428130969
CODE-128:3096140900557

Do you know how I can tell bash to kill zbarcam after printing on the stdout the first \n ?

+1  A: 

Try

tmp=/tmp/barcode.$$ # Note: security risk
zbarcam > $tmp &
pid=$!
# Sleep until file has content
while [[ ! -s $tmp ]] ; do
    sleep 1
done
kill $pid
cat $tmp

Note that it might not work if zbarcam doesn't flush its output.

Aaron Digulla
Thank you, It works well !
Natim
+1  A: 

Have you tried this?

zbarcam | head -1 | xvkbd -file - -window emacs
retracile
It just stop to write on the virtual keyboard but doesn't stop zbarcam.
Natim
Ok, the technique works for some things, but not everything. Glad you got another answer that worked for you.
retracile
A: 

tmp=/tmp/barcode.$$ # Note: security risk zbarcam > $tmp & pid=$!

Sleep until file has content

while [[ ! -s $tmp ]] ; do sleep 1 done kill $pid cat $tmp

Very Good :D

Junior