有人可以发布一个在 Linux 上的 Bash 中使用命名管道的简单示例吗?
最佳答案
命名管道实际使用的最佳示例之一...
来自 http://en.wikipedia.org/wiki/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
Port 12345 represents the request.
This starts a
nc
server on port 12345 and all the connections get redirected togoogle.com:80
. If a web browser makes a request tonc
, 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 - 在 Linux shell (Bash) 中使用命名管道的示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4113986/