Created
April 19, 2010 23:00
-
-
Save adamwiggins/371776 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
# Using PTY instead of IO.popen, see answer: | |
# http://stackoverflow.com/questions/1154846/continuously-read-from-stdout-of-external-process-in-ruby | |
def spawn_command(command) | |
begin | |
PTY.spawn(command) do |stdin, stdout, pid| | |
Process.wait(pid) | |
begin | |
stdin.each { |line| message " #{line}" } | |
rescue Errno::EIO | |
# child process stopped giving input | |
end | |
end | |
return $?.exitstatus | |
rescue PTY::ChildExited => e | |
return e.status | |
# child process exited | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment