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/version.rb,
lib/childprocess/windows.rb,
lib/childprocess/jruby/io.rb,
lib/childprocess/jruby/pump.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/windows/functions.rb
Defined Under Namespace
Modules: JRuby, Unix, Windows
Classes: AbstractIO, AbstractProcess, Error, InvalidEnvironmentVariableName, LaunchError, SubclassResponsibility, TimeoutError
Constant Summary
collapse
- VERSION =
"0.2.5"
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.
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/childprocess.rb', line 85
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
44
45
46
|
# File 'lib/childprocess.rb', line 44
def jruby?
platform == :jruby
end
|
.jruby_on_unix? ⇒ Boolean
48
49
50
51
52
53
54
|
# File 'lib/childprocess.rb', line 48
def jruby_on_unix?
return false unless jruby?
require "java"
name = java.lang.System.getProperty("os.name").downcase
name =~ /mac os|linux|solaris|bsd/
end
|
.new(*args) ⇒ Object
Also known as:
build
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/childprocess.rb', line 12
def new(*args)
case platform
when :jruby
JRuby::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
|
.os ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/childprocess.rb', line 60
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
|
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/childprocess.rb', line 26
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
40
41
42
|
# File 'lib/childprocess.rb', line 40
def unix?
!jruby? && [:macosx, :linux, :unix].include?(os)
end
|
.windows? ⇒ Boolean
56
57
58
|
# File 'lib/childprocess.rb', line 56
def windows?
!jruby? && os == :windows
end
|