Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
904 views
in Technique[技术] by (71.8m points)

redirect - Redirecting bash stdout/stderr to two places?

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…)

question from:https://stackoverflow.com/questions/670784/redirecting-bash-stdout-stderr-to-two-places

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...