Skip to content

Instantly share code, notes, and snippets.

@mguterl
Created September 28, 2008 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mguterl/13466 to your computer and use it in GitHub Desktop.
Save mguterl/13466 to your computer and use it in GitHub Desktop.
WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
def quiet( &block )
io = [STDOUT.dup, STDERR.dup]
STDOUT.reopen DEV_NULL
STDERR.reopen DEV_NULL
block.call
ensure
STDOUT.reopen io.first
STDERR.reopen io.last
$stdout, $stderr = STDOUT, STDERR
end
DIFF = if WIN32 then 'diff.exe'
else
if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
else 'diff' end
end unless defined? DIFF
SUDO = if WIN32 then ''
else
if quiet {system 'which sudo'} then 'sudo'
else '' end
end
puts "foo" # this does not print under JRuby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment