Skip to content

Instantly share code, notes, and snippets.

@yorzi
Created February 15, 2012 01:45
Show Gist options
  • Save yorzi/1832427 to your computer and use it in GitHub Desktop.
Save yorzi/1832427 to your computer and use it in GitHub Desktop.
get command output in ruby code
require 'pty'
cmd = "rake -T"
begin
PTY.spawn( cmd ) do |stdin, stdout, pid|
begin
# Do stuff with the output here. Just printing to show it works
stdin.each { |line| print line }
rescue Errno::EIO
puts "Errno:EIO error, but this probably just means " +
"that the process has finished giving output"
end
end
rescue PTY::ChildExited
puts "The child process exited!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment