Is there a 'Y' (i.e. branch) version of a command pipe?

Modulok modulok at gmail.com
Sun Jan 9 03:30:09 UTC 2011


List,

Is there a command that lets me send standard input to two different
places at the same time? (i.e. non-sequentially.) Think of it like a
pipe character, but with a 'Y' branch instead. Basically, I want to
record standard input to a log file, but also send it to another
command for processing.

For example, let's assume we have a command called 'branch' and it
copies standard input to the standard input of all arguments. We could
use it like this:

cat foo.txt | branch '/bin/echo > log1.txt' '/bin/echo > log2.txt'

The first 'cat' would read the file, pass it to our theoretical
'branch' command, which would then start two subprocesses, passing the
input to both of them. The result result would be two copies of the
file. (Obviously making copies of files is not my primary goal, just
an example.)

I guess another way of explaining it would be two write the same stdin
to two named pipes and then have two different programs read from each
pipe, getting the same output.

I can probably write something in Python, but thought I'd ask first. Thanks!
-Modulok-


More information about the freebsd-questions mailing list