Skip to content

Instantly share code, notes, and snippets.

@pat
Created December 1, 2009 08:00
Show Gist options
  • Save pat/246154 to your computer and use it in GitHub Desktop.
Save pat/246154 to your computer and use it in GitHub Desktop.
# So, with some help (and perhaps some faulty testing on my part initially) here
# is a solution I'm happy with.
def sphinx_version
# STDERR redirection for Unix
stderr = $stderr.dup
read, write = IO.pipe
$stderr.reopen(write)
`indexer`[/^Sphinx (\d\.\d\.\d)/, 1]
rescue # This catches errors for Windows
nil
ensure
$stderr.reopen(stderr)
end
# This is a combination of suggestions from Loren Segal in Montreal and Aman
# Gupta from San Francisco.
http://twitter.com/lsegal/statuses/6227142586
http://twitter.com/tmm1/status/6227225512
# There was also a strong solution from Lachie Cox of Sydney:
http://twitter.com/lachiecox/status/6229025008
http://gist.github.com/246149
# Others suggested using open3, which unfortunately doesn't work on Windows.
# Thanks all for your ideas and help, very much appreciated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment