By default, a child process will inherit open file descriptors from the parent process. This helper provides a cross-platform way of making sure that doesn't happen for the given file/io.
# File lib/childprocess.rb, line 89 def close_on_exec(file) if file.respond_to?(:close_on_exec=) file.close_on_exec = true elsif file.respond_to?(:fcntl) && defined?(Fcntl::FD_CLOEXEC) file.fcntl Fcntl::F_SETFD, Fcntl::FD_CLOEXEC elsif windows? Windows.dont_inherit file else raise Error, "not sure how to set close-on-exec for #{file.inspect} on #{platform.inspect}" end end
# File lib/childprocess.rb, line 48 def jruby? platform == :jruby end
# File lib/childprocess.rb, line 52 def jruby_on_unix? return false unless jruby? # patterns grabbed from http://lopica.sourceforge.net/os.html require "java" name = java.lang.System.getProperty("os.name").downcase name =~ %rmac os|linux|solaris|bsd/ end
# File lib/childprocess.rb, line 14 def new(*args) case platform when :jruby JRuby::Process.new(args) when :ironruby IronRuby::Process.new(args) when :windows Windows::Process.new(args) when :macosx, :linux, :unix, :cygwin Unix::Process.new(args) else raise Error, "unsupported platform #{platform.inspect}" end end
# File lib/childprocess.rb, line 64 def os @os ||= ( require "rbconfig" host_os = RbConfig::CONFIG['host_os'] case host_os when %rmswin|msys|mingw32|cygwin/ :windows when %rdarwin|mac os/ :macosx when %rlinux/ :linux when %rsolaris|bsd/ :unix else raise Error, "unknown os: #{host_os.inspect}" end ) end
# File lib/childprocess.rb, line 30 def platform if RUBY_PLATFORM == "java" :jruby elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == "ironruby" :ironruby elsif RUBY_PLATFORM =~ %rmswin|msys|mingw32/ :windows elsif RUBY_PLATFORM =~ %rcygwin/ :cygwin else os end end
# File lib/childprocess.rb, line 44 def unix? !jruby? && [:macosx, :linux, :unix].include?(os) end
# File lib/childprocess.rb, line 60 def windows? !jruby? && os == :windows end