Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k 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 Answer

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...