linux - 在 Linux shell (Bash) 中使用命名管道的示例

标签 linux bash shell pipe named-pipes

有人可以发布一个在 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 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 - 在 Linux shell (Bash) 中使用命名管道的示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4113986/

相关文章:

linux - 如何拆分字符串并使用 cut 打印所有子字符串

linux - 如果汇编程序中没有退出系统调用会怎样?

关闭终端时 Bash 脚本无法正常运行

bash - 如何在 bash 脚本中保留文件夹结构?

php - xsl文件从linux服务器加载到php中

c - 使用 C 退出到 linux 的 ssh session

regex - 在 Bash 中使用逗号分隔的字符串作为变量的输入

linux - 使用 bash $ 命令执行 vi

json - 将键和值从 jq 传递给外部命令

python - 使用 subprocess call/popen 从另一个 python 脚本执行 python 脚本