I’d like to redirect the stdout of process proc1 to two processes proc2 and proc3:
proc2 -> stdout / proc1 \ proc3 -> stdout
I tried
proc1 | (proc2 & proc3)
but it doesn’t seem to work, i.e.
echo 123 | (tr 1 a & tr 1 b)
writes
b23
to stdout instead of
a23 b23
Editor’s note:
–
>(…)is a process substitution that is a nonstandard shell feature of some POSIX-compatible shells:bash,ksh,zsh.– This answer accidentally sends the output process substitution’s output through the pipeline too:
echo 123 | tee >(tr 1 a) | tr 1 b.– Output from the process substitutions will be unpredictably interleaved, and, except in
zsh, the pipeline may terminate before the commands inside>(…)do.In unix (or on a mac), use the
teecommand:Usually you would use
teeto redirect output to multiple files, but using >(…) you can redirect to another process. So, in general,will do what you want.
Under windows, I don’t think the built-in shell has an equivalent. Microsoft’s Windows PowerShell has a
teecommand though.