Skip to content

Instantly share code, notes, and snippets.

@rickhull
Last active August 29, 2015 14:23
Show Gist options
  • Save rickhull/cf5501100daa7e26780a to your computer and use it in GitHub Desktop.
Save rickhull/cf5501100daa7e26780a to your computer and use it in GitHub Desktop.
#!/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