将bash stdout / stderr重定向到两个地方?(Redirecting bash stdout/stderr to two places?)

编程入门 行业动态 更新时间:2024-10-23 18:20:30
将bash stdout / stderr重定向到两个地方?(Redirecting bash stdout/stderr to two places?)

这个人一直在窃听我一段时间。 是否有可能将stdout和stderr重定向到终端输出程序?

我知道有可能将输出重定向到一个文件并使用tee进行stdout ,但我希望它能够进入一个程序(我的编辑器[TextMate])以及终端输出...当然这是可能的(我知道它是可能的用zsh ...)

This one's been bugging me for a while now. Is it possible to redirect stdout and stderr to both the terminal output and to a program?

I understand it's possible to redirect the outputs to a file and to stdout with tee, but I want it to go to a program (my editor [TextMate]) as well as to the terminal output… surely this is possible (I know its possible with zsh…)

最满意答案

您可以使用命名管道,该管道专门用于您描述的情况。

mkfifo some_pipe command_that_writes_to_stdout | tee some_pipe \ & command_that_reads_from_stdin < some_pipe rm some_pipe

或者,在Bash中:

command_that_writes_to_stdout | tee >(command_that_reads_from_stdin)

You can use a named pipe, which is intended for exactly the situation you describe.

mkfifo some_pipe command_that_writes_to_stdout | tee some_pipe \ & command_that_reads_from_stdin < some_pipe rm some_pipe

Or, in Bash:

command_that_writes_to_stdout | tee >(command_that_reads_from_stdin)

更多推荐

本文发布于:2023-07-31 00:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340547.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   两个   地方   stdout   bash

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!