Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting bash stdout/stderr to two places?

Tags:

redirect

bash

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

like image 601
obeattie Avatar asked Mar 22 '09 10:03

obeattie


1 Answers

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) 
like image 139
JasonSmith Avatar answered Sep 30 '22 07:09

JasonSmith