Skip to content

Instantly share code, notes, and snippets.

@stonegao
Forked from pat/gist:246100
Created December 1, 2009 06:56
Show Gist options
  • Save stonegao/246120 to your computer and use it in GitHub Desktop.
Save stonegao/246120 to your computer and use it in GitHub Desktop.
# I want to check if Sphinx is installed on machines to auto-determine the
# version. This can be done via the following line of code:
`indexer`[/^Sphinx (\d\.\d\.\d)/, 1]
# But, if indexer doesn't exist, then we get an error sent to the shell by Ruby
# (though it's not caught by $stdout/$stderr, so I assume it's core Ruby being
# inconsistent).
#
# I don't want the error - I have code in place to let the user know that
# indexer isn't there.
#
# Attempted workarounds:
# * system('indexer') sends the output to STDOUT on failure, and straight to the
# shell on success.
# * `indexer 2>/dev/null` isn't Windows friendly.
#
# So, what do I want? Code that checks for the existence of indexer, and runs it
# for the version output if it is there, otherwise returns nil, without ever
# printing anything to shell/STDOUT/STDERR, and works on Windows as well as Unix
# systems. Any suggestions?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment