[英]How to ask bash to wait for a result and send a SIGKILL when it get it?
I want to use zbarcam but after reading a barcode, it doesn't stop. 我想使用zbarcam,但是读取条形码后,它并没有停止。
$ 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 ? 您知道我如何告诉bash在标准输出上第一个\\ n打印后杀死zbarcam吗?
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. 请注意,如果zbarcam不刷新其输出,它可能不起作用。
你有尝试过吗?
zbarcam | head -1 | xvkbd -file - -window emacs
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.