如何要求 bash 等待结果并在收到结果时发送 SIGKILL?

发布于 2024-08-08 00:59:33 字数 195 浏览 3 评论 0原文

我想使用 zbarcam,但读取条形码后,它不会停止。

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

你知道在标准输出上打印第一个 \n 后如何告诉 bash 杀死 zbarcam 吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

于我来说 2024-08-15 00:59:33

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

注意,如果 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.

一瞬间的火花 2024-08-15 00:59:33

你试过这个吗?

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

Have you tried this?

zbarcam | head -1 | xvkbd -file - -window emacs
浮世清欢 2024-08-15 00:59:33
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
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文