#!/usr/bin/ruby # mpipe reads STDIN and pipes it to multiple processes # # Usage: whatever | rpipe.rb -pipe pgm1 -pipe pgm2 -p 1 -d toto -pipe pgm3 -x # # pgm1, pgm2 and pgm3 will all receive whatever's STDOUT on their STDIN # # Current limitation: programs that expect a -pipe argument themselves cannot be called # # Target usage: send CVS loginfo to multiple processes # Look for -pipe ... in ARGV aPipes=[] curr="" ARGV.each {|p| if p == '-pipe' # We have got a pipe cmd aPipes << IO.popen(curr, "w") if curr.length > 0 # Start next pipe curr="" else curr << p << " " # Add argument to current pipe cmd end } # Last cmd aPipes << IO.popen(curr, "w") if curr.length > 0 # Read STDIN and send it to all opened pipes STDIN.each { |line| aPipes.each { |p| p.puts(line) } } # Close all pipes and exit aPipes.each {|p| p.close_write}