How do I ask bash to wait for the result and send a SIGKILL when it receives it?

I want to use zbarcam but after reading the 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 to stdout first \ n?

+2


source to share


3 answers


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 this may not work if zbarcam does not flush its output.

+1


source


Have you tried this?



zbarcam | head -1 | xvkbd -file - -window emacs

      

+1


source


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

      

-1


source







All Articles