Example of using named pipes in Linux Bash

前端 未结 4 534
一向
一向 2020-12-02 05:36

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

4条回答
  •  伪装坚强ぢ
    2020-12-02 06:27

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

    From 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 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  0backpipe
    

提交回复
热议问题