#!/usr/bin/env ruby cmd = "for i in {1..30}; do echo '123456789'; done" pipe_in, pipe_out = IO.pipe pid = Process.spawn(cmd, :out => pipe_out, :err => pipe_out) Process.wait pid pipe_out.close puts pipe_in.read