mkfifo causes terminal to hang?

梦想与她 提交于 2019-12-20 04:04:17

问题


Does mkfifo simply not work with Cygwin? A simple set of commands such as

$ mkfifo my_pipe

$ echo "1234" > my_pipe

just causes the terminal to sit forever with the cursor blinking. Am I "doing it wrong"?


回答1:


No, you're not doing anything wrong with either of those commands, it's just your expectations are a little off.

What you're missing is something at the other end of that pipe, reading that data. This apparent hanging happens in Linux as well, so it's not a CygWin problem (or any sort of problem, really).

Just open up another window and enter:

cat <my_pipe

and you'll see the data appear, followed by the original echo completing.




回答2:


The thing with named pipes is that you need to have something on both ends. You can't write into a pipe if it isn't complete yet, so the echo command hangs until something else tries to read from that pipe, which in your case never happens.



来源:https://stackoverflow.com/questions/12667621/mkfifo-causes-terminal-to-hang

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!