Module: ChildProcess

### Home Classes Methods

### In Files

- lib/childprocess.rb
- lib/childprocess/abstract_io.rb
- lib/childprocess/abstract_process.rb
- lib/childprocess/errors.rb
- lib/childprocess/jruby.rb
- lib/childprocess/jruby/io.rb
- lib/childprocess/jruby/process.rb
- lib/childprocess/jruby/pump.rb
- lib/childprocess/tools/generator.rb
- lib/childprocess/unix.rb
- lib/childprocess/unix/fork_exec_process.rb
- lib/childprocess/unix/io.rb
- lib/childprocess/unix/lib.rb
- lib/childprocess/unix/posix_spawn_process.rb
- lib/childprocess/unix/process.rb
- lib/childprocess/version.rb
- lib/childprocess/windows.rb
- lib/childprocess/windows/handle.rb
- lib/childprocess/windows/io.rb
- lib/childprocess/windows/lib.rb
- lib/childprocess/windows/process.rb
- lib/childprocess/windows/process_builder.rb
- lib/childprocess/windows/structs.rb

### Namespace

- MODULE ChildProcess::JRuby
- MODULE ChildProcess::Tools
- MODULE ChildProcess::Unix
- MODULE ChildProcess::Windows
- CLASS ChildProcess::AbstractIO
- CLASS ChildProcess::AbstractProcess
- CLASS ChildProcess::Error
- CLASS ChildProcess::InvalidEnvironmentVariable
- CLASS ChildProcess::LaunchError
- CLASS ChildProcess::MissingPlatformError
- CLASS ChildProcess::SubclassResponsibility
- CLASS ChildProcess::TimeoutError

### Methods

- ::arch
- ::build
- ::close_on_exec
- ::jruby?
- ::linux?
- ::new
- ::os
- ::platform
- ::platform_name
- ::posix_spawn=
- ::posix_spawn?
- ::unix?
- ::windows?

### Class/Module Index

Quicksearch

- ChildProcess
- ChildProcess::AbstractIO
- ChildProcess::AbstractProcess
- ChildProcess::Error
- ChildProcess::InvalidEnvironmentVariable
- ChildProcess::JRuby
- ChildProcess::JRuby::IO
- ChildProcess::JRuby::Process
- ChildProcess::JRuby::Pump
- ChildProcess::LaunchError
- ChildProcess::MissingPlatformError
- ChildProcess::SubclassResponsibility
- ChildProcess::TimeoutError
- ChildProcess::Tools
- ChildProcess::Tools::Generator
- ChildProcess::Unix
- ChildProcess::Unix::ForkExecProcess
- ChildProcess::Unix::IO
- ChildProcess::Unix::Lib
- ChildProcess::Unix::Lib::Attrs
- ChildProcess::Unix::Lib::FileActions
- ChildProcess::Unix::Platform
- ChildProcess::Unix::PosixSpawnProcess
- ChildProcess::Unix::PosixSpawnProcess::Argv
- ChildProcess::Unix::PosixSpawnProcess::Envp
- ChildProcess::Unix::Process
- ChildProcess::Windows
- ChildProcess::Windows::Handle
- ChildProcess::Windows::IO
- ChildProcess::Windows::IoCounters
- ChildProcess::Windows::JobObjectBasicLimitInformation
- ChildProcess::Windows::JobObjectExtendedLimitInformation
- ChildProcess::Windows::Lib
- ChildProcess::Windows::Process
- ChildProcess::Windows::Process::Job
- ChildProcess::Windows::ProcessBuilder
- ChildProcess::Windows::ProcessInfo
- ChildProcess::Windows::SecurityAttributes
- ChildProcess::Windows::StartupInfo
- Java
- Java::JavaIo
- Java::JavaIo::FileDescriptor
- Java::SunNioCh
- Java::SunNioCh::FileChannelImpl
- FFI
- FFI::MemoryPointer

No matching classes.

# ChildProcess

### Constants

VERSION

### Public Class Methods

arch() click to toggle source

    # File lib/childprocess.rb, line 113
    def arch
      @arch ||= (
        host_cpu = RbConfig::CONFIG['host_cpu'].downcase
        case host_cpu
        when /i[3456]86/
          # Darwin always reports i686, even when running in 64bit mod
          if os == :macosx && 0xfee1deadbeef.is_a?(Fixnum)
            "x86_64"
          else
            "i386"
          end
        when /amd64|x86_64/
          "x86_64"
        when /ppc|powerpc/
          "powerpc"
        else
          host_cpu
        end
      )
    end

build(*args) click to toggle source
Alias for: new
close_on_exec(file) click to toggle source

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 140
    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

        if jruby? && posix_spawn?
          # on JRuby, the fcntl call above apparently isn't enough when
          # we're launching the process through posix_spawn.
          fileno = JRuby.posix_fileno_for(file)
          Unix::Lib.fcntl fileno, Fcntl::F_SETFD, Fcntl::FD_CLOEXEC
        end
      elsif windows?
        Windows::Lib.dont_inherit file
      else
        raise Error, "not sure how to set close-on-exec for #{file.inspect} on #{platform_name.inspect}"
      end
    end

jruby?() click to toggle source

    # File lib/childprocess.rb, line 51
    def jruby?
      platform == :jruby
    end

linux?() click to toggle source

    # File lib/childprocess.rb, line 47
    def linux?
      os == :linux
    end

new(*args) click to toggle source

    # File lib/childprocess.rb, line 11
    def new(*args)
      case os
      when :macosx, :linux, :solaris, :bsd, :cygwin, :aix
        if posix_spawn?
          Unix::PosixSpawnProcess.new(args)
        elsif jruby?
          JRuby::Process.new(args)
        else
          Unix::ForkExecProcess.new(args)
        end
      when :windows
        Windows::Process.new(args)
      else
        raise Error, "unsupported platform #{platform_name.inspect}"
      end
    end

Also aliased as: build
os() click to toggle source

    # File lib/childprocess.rb, line 87
    def os
      @os ||= (
        require "rbconfig"
        host_os = RbConfig::CONFIG['host_os'].downcase

        case host_os
        when /linux/
          :linux
        when /darwin|mac os/
          :macosx
        when /mswin|msys|mingw32/
          :windows
        when /cygwin/
          :cygwin
        when /solaris|sunos/
          :solaris
        when /bsd/
          :bsd
        when /aix/
          :aix
        else
          raise Error, "unknown os: #{host_os.inspect}"
        end
      )
    end

platform() click to toggle source

    # File lib/childprocess.rb, line 29
    def platform
      if RUBY_PLATFORM == "java"
        :jruby
      elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == "ironruby"
        :ironruby
      else
        os
      end
    end

platform_name() click to toggle source

    # File lib/childprocess.rb, line 39
    def platform_name
      @platform_name ||= "#{arch}-#{os}"
    end

posix_spawn=(bool) click to toggle source

Set this to true to enable experimental use of posix_spawn.

    # File lib/childprocess.rb, line 83
    def posix_spawn=(bool)
      @posix_spawn = bool
    end

posix_spawn?() click to toggle source

    # File lib/childprocess.rb, line 59
    def posix_spawn?
      enabled = @posix_spawn || ]1 true].include?(ENV['CHILDPROCESS_POSIX_SPAWN'])
      return false unless enabled

      require 'ffi'
      begin
        require "childprocess/unix/platform/#{ChildProcess.platform_name}"
      rescue LoadError
        raise ChildProcess::MissingPlatformError
      end

      require "childprocess/unix/lib"
      require 'childprocess/unix/posix_spawn_process'

      true
    rescue ChildProcess::MissingPlatformError => ex
      warn_once ex.message
      false
    end

unix?() click to toggle source

    # File lib/childprocess.rb, line 43
    def unix?
      !windows?
    end

windows?() click to toggle source

    # File lib/childprocess.rb, line 55
    def windows?
      os == :windows
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.