英文:
How can I only pipe the stdout to another command, and redirecting stderr to the standard out of the terminal?
问题
我有一个名为 `foo` 的命令,我想将其 `stdout` 管道传输到另一个名为 `bar` 的命令,其输出我想要管道传输到 `bas`。如果 `foo` 失败,我希望在控制台的默认标准输出中看到它。最佳方法是什么?
对于澄清,如果 `foo` 以 stderr 输出失败,我希望直接将其作为结果看到,而不是被 `bar` 或 `bas` 处理。
$ foo | bar | bas
This is error written to stderr by foo.
英文:
I have a command foo
whose stdout
I want to pipe to another command bar
, whose output I want to pipe to bas
. If foo
fails, I want to see it in the default standard out of the console. What is the best approach?
$ foo | bar | bas
For clarification, if foo
fails with output in the stderr, I want to see it directly as a result, and not being processed by bar
or bas
.
$ foo | bar | bas
This is error written to stderr by foo.
答案1
得分: 2
确保 "foo" 不在内部将 stderr 重定向到 stdout。
默认情况下,stderr 不会被路由到管道。
只有在以下情况下才会 "丢失" stderr 流:
foo 2>&1 | bar | bas
或者
foo |& bar | bas
英文:
Make sure that "foo" doesn't redirect stderr to stdout internally.
By default stderr is NOT routed to pipe.
You would only "lose" that stderr stream if you did either
foo 2>&1 | bar | bas
or
foo |& bar | bas
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论