无法写入命名管道 [英] Can't write to named pipe

查看:194
本文介绍了无法写入命名管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写一个命名管道,是 mkfifo子进行。但是,当我运行命令,(前) LS> myNamedPipe ,我不能再输入命令进入庆典。我仍然可以写人物,这就是pretty多了。

I'm trying to write to a named pipe, made with mkfifo. But when I run the command, (ex) ls > myNamedPipe, I can no longer enter commands into the bash. I can still write characters and that's pretty much it.

推荐答案

一个命名管道保持打开状态,直到你从别的地方读它。这是为了允许不同进程之间的通信。

A named pipe remains opened until you read it from some other place. This is to permit communication between different processes.

尝试:

mkfifo fifo
echo "foo" > fifo

然后打开另一个终端,输入:

Then open another terminal and type:

cat fifo

如果您返回到您第一终端,你会发现,你现在就可以输入其他命令。

If you return to you first terminal, you'll notice that you can now enter other commands.

另见什么与反向happends:

See also what happends with the reverse :

# terminal 1
cat fifo

# terminal 2
echo "foo" > fifo

# and now you can see "foo" on terminal 1

如果你想你的终端不尝试写一些东西到FIFO时,附加到FIFO文件描述符上挂起:

If you want you terminal not to "hang on" when trying to write something to the fifo, attach to the fifo a file descriptor :

mkfifo fifo
exec 3<> fifo
echo "foo" > fifo
echo "bar" > fifo

这篇关于无法写入命名管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆