Last active
August 29, 2015 14:23
-
-
Save rickhull/cf5501100daa7e26780a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'open3' | |
module TestingStuff | |
# return Process::Status, stream through STDOUT and STDERR | |
def self.exec(cmd, bytes=1024) | |
Open3.popen3(cmd) { |sin, sout, serr, thr| | |
sin.close_write | |
while !sout.eof or !serr.eof | |
ready = IO.select [sout, serr] | |
if ready | |
ready[0].each { |f| # ready for reading | |
begin | |
(f == sout ? $stdout : $stderr).print f.read_nonblock(bytes) | |
rescue EOFError => e | |
# ok | |
end | |
} | |
end | |
end | |
thr.value # Process::Status | |
} | |
end | |
end | |
cmd = ARGV.shift || raise("please provide a quoted command") | |
status = TestingStuff.exec(cmd) | |
puts "DONE: #{status}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment