Created
February 15, 2012 01:45
-
-
Save yorzi/1832427 to your computer and use it in GitHub Desktop.
get command output in ruby code
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
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