How to avoid echo closing FIFO named pipes? - Funny behavior of Unix FIFOs

前端 未结 6 1570
面向向阳花
面向向阳花 2020-12-04 08:10

I want to output some data to a pipe and have the other process do something to the data line by line. Here is a toy example:

mkfifo pipe
cat pipe&
cat &         


        
6条回答
  •  执念已碎
    2020-12-04 09:01

    Honestly, the best way I was able to get this to work was by using socat, which basically connections two sockets.

    mkfifo foo
    socat $PWD/foo /dev/tty
    

    Now in a new term, you can:

    echo "I am in your term!" > foo
    # also (surprisingly) this works
    clear > foo
    

    The downside is you need socat, which isn't a basic util everyone gets. The plus side is, I can't find something that doesn't work... I am able to print colors, tee to the fifo, clear the screen, etc. It is as if you slave the whole terminal.

提交回复
热议问题