Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tee a Pipe Asynchronously

Tags:

linux

bash

I would like to write the same information to two pipes, but I don't want to wait for the first pipe to read. Here's an example

mkfifo one
mkfifo two
echo hi | tee one two &
cat one &
cat two &

cat one does not start reading until cat two is run. Is there a way to make cat one run without waiting?

like image 483
User1 Avatar asked Feb 02 '26 09:02

User1


1 Answers

Problem: Fifos are blocking until opened for reading. So just open a read FD on them:

mkfifo one two
echo hi | tee one two &
exec 3<one
exec 4<two
cat <&3
cat <&4
like image 173
Jürgen Hötzel Avatar answered Feb 05 '26 05:02

Jürgen Hötzel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!