How to write data to existing process's STDIN from external process?

后端 未结 2 1867
孤独总比滥情好
孤独总比滥情好 2020-11-30 04:05

I\'m seeking for ways to write data to the existing process\'s STDIN from external processes, and found similar question How do you stream data into the STDIN

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 04:34

    I want to leave here an example I found useful. It's a slight modification of the while true trick above that failed intermittently on my machine.

    # pipe cat to your long running process
    ( cat ) | ./your_server &
    server_pid=$!
    # send an echo to your cat process that will close cat and in my hypothetical case the server too
    echo "quit\n" > "/proc/$server_pid/fd/0"
    

    It was helpful to me because for particular reasons I couldn't use mkfifo, which is perfect for this scenario.

提交回复
热议问题