使用两个不同的脚本从FIFO进行写入和读取 [英] Write and read from a fifo from two different script
本文介绍了使用两个不同的脚本从FIFO进行写入和读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个bash脚本. 一个脚本用fifo编写.第二个从fifo读取,但是在第一个结束后写入.
I have two bash script. One script write in a fifo. The second one read from the fifo, but AFTER the first one end to write.
但是有些东西行不通.我不明白问题出在哪里.这里是代码.
But something does not work. I do not understand where the problem is. Here the code.
第一个脚本是(作者):
The first script is (the writer):
#!/bin/bash
fifo_name="myfifo";
# Se non esiste, crea la fifo;
[ -p $fifo_name ] || mkfifo $fifo_name;
exec 3<> $fifo_name;
echo "foo" > $fifo_name;
echo "bar" > $fifo_name;
第二个脚本是(读者):
The second script is (the reader):
#!/bin/bash
fifo_name="myfifo";
while true
do
if read line <$fifo_name; then
# if [[ "$line" == 'ar' ]]; then
# break
#fi
echo $line
fi
done
有人可以帮我吗? 谢谢
Can anyone help me please? Thank you
推荐答案
将第二个脚本替换为:
#!/bin/bash
fifo_name="myfifo"
while true
do
if read line; then
echo $line
fi
done <"$fifo_name"
这只会打开fifo一次,并从中读取每一行.
This opens the fifo only once and reads every line from it.
这篇关于使用两个不同的脚本从FIFO进行写入和读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文