在Linux中的Bash使用命名管道的实例 [英] Example of using named pipes in Linux Bash

查看:121
本文介绍了在Linux中的Bash使用命名管道的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以发布使用Bash的命名管道在Linux中的一个简单的例子?

Can someone post a simple example of using named pipes in Bash in Linux?

推荐答案

其中的实际使用命名管道的一个最好的例子...

One of the best examples of a practical use of a named pipe...

通过 http://en.wikipedia.org/wiki/Netcat

另一个有用的特性是使用的netcat作为代理。两个端口和主机可以重定向。请看下面的例子:

Another useful behavior is using netcat as a proxy. Both ports and hosts can be redirected. Look at this example:

nc -l 12345 | nc www.google.com 80

12345端口重新presents请求
这将启动在端口12345数控服务器和所有连接重定向到google.com:80~~V。如果网络浏览器向数控一个请求,该请求将被发送到google但反应将不被发送到网络浏览器。这是因为管道是单向的。这可以被加工围绕与命名管道重定向的输入和输出。

Port 12345 represents the request This starts a nc server on port 12345 and all the connections get redirected to google.com:80. If a web browser makes a request to nc, the request will be sent to google but the response will not be sent to the web browser. That is because pipes are unidirectional. This can be worked around with a named pipe to redirect the input and output.

mkfifo backpipe
nc -l 12345  0<backpipe | nc www.google.com 80 1>backpipe

这篇关于在Linux中的Bash使用命名管道的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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