aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorSam Stephenson <sam@37signals.com>2005-11-07 00:37:32 +0000
committerSam Stephenson <sam@37signals.com>2005-11-07 00:37:32 +0000
commit645de3391276a654ab4a653f5bbe47efc5759b77 (patch)
tree66b9c0f839d25f34a0575c4034d3d01a71bd1175 /activesupport/lib/active_support/core_ext
parent49c801b71d425543ae88e171b969b3316f022c2a (diff)
downloadrails-645de3391276a654ab4a653f5bbe47efc5759b77.tar.gz
rails-645de3391276a654ab4a653f5bbe47efc5759b77.tar.bz2
rails-645de3391276a654ab4a653f5bbe47efc5759b77.zip
Added Kernel#silence_stderr to silence stderr for the duration of the given block. Changed Kernel#` to print a message to stderr (like Unix) instead of raising Errno::ENOENT on Win32.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2899 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/kernel.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/kernel.rb b/activesupport/lib/active_support/core_ext/kernel.rb
index 168c9cddd3..310bba0904 100644
--- a/activesupport/lib/active_support/core_ext/kernel.rb
+++ b/activesupport/lib/active_support/core_ext/kernel.rb
@@ -29,6 +29,32 @@ module Kernel
$VERBOSE = old_verbose
end
+ # Silences stderr for the duration of the block.
+ #
+ # silence_stderr do
+ # $stderr.puts 'This will never be seen'
+ # end
+ #
+ # $stderr.puts 'But this will'
+ def silence_stderr
+ old_stderr = STDERR.dup
+ STDERR.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
+ STDERR.sync = true
+ yield
+ ensure
+ STDERR.reopen(old_stderr)
+ end
+
+ # Makes backticks behave (somewhat more) similarly on all platforms.
+ # On win32 `nonexistent_command` raises Errno::ENOENT; on Unix, the
+ # spawned shell prints a message to stderr and sets $?. We emulate
+ # Unix on the former but not the latter.
+ def `(command) #:nodoc:
+ super
+ rescue Errno::ENOENT => e
+ STDERR.puts "#$0: #{e}"
+ end
+
# Method that requires a library, ensuring that rubygems is loaded
def require_library_or_gem(library_name)
begin