Skip to content

Instantly share code, notes, and snippets.

@Kimtaro
Forked from pat/gist:246154
Created January 2, 2010 00:25
Show Gist options
  • Save Kimtaro/267318 to your computer and use it in GitHub Desktop.
Save Kimtaro/267318 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