Skip to content

Instantly share code, notes, and snippets.

@dholdren
Created October 6, 2014 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dholdren/8ff75b6001b80767951f to your computer and use it in GitHub Desktop.
Save dholdren/8ff75b6001b80767951f to your computer and use it in GitHub Desktop.
Stream output and capture it and exit status
#Stream output and capture it and exit status as well
require 'open3'
output = ''
exit_status = nil
Open3.popen2e('foobarwhat') {|stdin, stdout_and_stderr, wait_thread|
stdout_and_stderr.each{|line|
puts line
output += line
}
exit_status = wait_thread.value.exitstatus
}
#puts "captured output= #{output}"
puts "Exit Status: #{exit_status}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment