2 # -*- encoding: binary -*-
4 # An example of using IO.tee, this is a limited version of the standard
5 # "tee" utility that requires stdin and stdout to both be pipes.
8 usage = "filter_prog1 | #$0 DEST | filter_prog2"
9 dest = ARGV.shift or abort usage
10 $stdin.stat.pipe? or abort "stdin must be a pipe"
11 $stdout.stat.pipe? or abort "stdout must be a pipe"
13 dest = File.open(dest, 'wb')
17 # "copy" data from stdin to stdout, without consuming stdin
18 IO.tee($stdin, $stdout, IO::Splice::PIPE_CAPA, 0)
23 # sends data to the file, consumes stdin
24 nwritten = IO.splice($stdin, nil, dest, nil, nread, 0)
27 abort "short splice to file: #{nwritten} != #{nread}"