2
I am trying to use named pipes as a convenient way to preprocess input on the fly for pipelines that sadly do not accept data from stdin directly.
everywhere I look for info I get basically the same gist: Named pipes should be dead simple to use.
the gist is mostly that the following should work:
mkfifo mynamedpipe
echo "is this working?" > mynamedpipe
cat mynamedpipe
when i run mkfifo mynamedpipe
, the pipe is successfully created and visible with ls *
.
But even after i grant myself write permission to that pipe, when i try to run echo "whatever" > mynamedpipe
nothing happens and the terminal just hangs until I kill the process with ctrl+c
.
I have this problem on my local linux machine (Ubuntu 14.04.5 LTS) as well as on a public server (Red Hat Enterprise Linux 7), and in zsh as well as in bash.
What am I doing wrong here?
1
try
– Frank Thomas – 2018-09-06T16:57:06.610cat < mynamedpipe
. also note this quote from https://www.linuxjournal.com/article/2156 : "If you watch closely, you'll notice that the first command you run appears to hang. This happens because the other end of the pipe is not yet connected, and so the kernel suspends the first process until the second process opens the pipe. In Unix jargon, the process is said to be “blocked”, since it is waiting for something to happen."Thanks that clears things up for me. But it is annoying that virtually every tutorial on this matter (or at least all of the most prominent google hits) describes exactly the basic steps I posted above, stating that they should work "as-is", without ever addressing that problem. Is this something that changed in recent times? – jov14 – 2018-09-06T17:28:14.673
You should use the reader (
– dirkt – 2018-09-07T06:10:39.553cat mynamedpipe
) first. Which means you need two terminals. Also, this smells like an XY question. Please explain the actual problem you are trying to solve: What are those "pipelines that sadly do not accept data from stdin directly" exactly?