Module: ChildProcess

Defined in:
lib/childprocess.rb,
lib/childprocess/unix.rb,
lib/childprocess/jruby.rb,
lib/childprocess/errors.rb,
lib/childprocess/unix/io.rb,
lib/childprocess/windows.rb,
lib/childprocess/ironruby.rb,
lib/childprocess/jruby/io.rb,
lib/childprocess/windows/io.rb,
lib/childprocess/abstract_io.rb,
lib/childprocess/windows/api.rb,
lib/childprocess/unix/process.rb,
lib/childprocess/jruby/process.rb,
lib/childprocess/windows/handle.rb,
lib/childprocess/windows/process.rb,
lib/childprocess/abstract_process.rb,
lib/childprocess/ironruby/process.rb,
lib/childprocess/jruby/redirector.rb,
lib/childprocess/windows/functions.rb

Defined Under Namespace

Modules: IronRuby, JRuby, Unix, Windows Classes: AbstractIO, AbstractProcess, Error, SubclassResponsibility, TimeoutError

Class Method Summary collapse

Class Method Details

.close_on_exec(file) ⇒ Object

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.



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/childprocess.rb', line 81

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

.jruby?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/childprocess.rb', line 48

def jruby?
  platform == :jruby
end

.new(*args) ⇒ Object Also known as: build



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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

.osObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/childprocess.rb', line 56

def os
  @os ||= (
    require "rbconfig"
    host_os = RbConfig::CONFIG['host_os']

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

.platformObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/childprocess.rb', line 30

def platform
  if RUBY_PLATFORM == "java"
    :jruby
  elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == "ironruby"
    :ironruby
  elsif RUBY_PLATFORM =~ /mswin|msys|mingw32/
    :windows
  elsif RUBY_PLATFORM =~ /cygwin/
    :cygwin
  else
    os
  end
end

.unix?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/childprocess.rb', line 44

def unix?
  !jruby? && [:macosx, :linux, :unix].include?(os)
end

.windows?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/childprocess.rb', line 52

def windows?
  !jruby? && os == :windows
end