This is how I detect git in ruby:
`which git 2>/dev/null` and $?.success?
However, this is not cross-platform. It does not work on systems without unix or without which command (although I'm not sure what it is).
I need a git detection method that satisfies these conditions:
- works on cross platform platform even on Windows
- doesn't display anything in $ stdout or $ stderr
- small amount of code
Update: The solution is to avoid using which in general and redirect the output to NUL on Windows.
require 'rbconfig' void = RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw/ ? 'NUL' : '/dev/null' system "git --version >>#{void} 2>&1"
The system command returns true on success and false on error, saving us the transition to $?.success? which is necessary when using feedback signals.
git windows ruby shell detect
mislav
source share