Sha256: 1cf4ed42c20c1954321499a7975cdb8e30221b270d7612c926659ad23bee08b4
Contents?: true
Size: 793 Bytes
Versions: 14
Compression:
Stored size: 793 Bytes
Contents
#!/usr/bin/env ruby # -*- encoding: binary -*- # An example of using IO.tee, this is a limited version of the standard # "tee" utility that requires stdin and stdout to both be pipes. require 'io/splice' usage = "filter_prog1 | #$0 DEST | filter_prog2" dest = ARGV.shift or abort usage $stdin.stat.pipe? or abort "stdin must be a pipe" $stdout.stat.pipe? or abort "stdout must be a pipe" dest = File.open(dest, 'wb') begin nread = begin # "copy" data from stdin to stdout, without consuming stdin IO.tee($stdin, $stdout, IO::Splice::PIPE_CAPA, 0) rescue EOFError break end # sends data to the file, consumes stdin nwritten = IO.splice($stdin, nil, dest, nil, nread, 0) nwritten == nread or abort "short splice to file: #{nwritten} != #{nread}" end while true
Version data entries
14 entries across 14 versions & 1 rubygems