Module: ChildProcess
- Defined in:
- lib/childprocess.rb,
lib/childprocess/unix.rb,
lib/childprocess/errors.rb,
lib/childprocess/unix/io.rb,
lib/childprocess/version.rb,
lib/childprocess/windows.rb,
lib/childprocess/windows/io.rb,
lib/childprocess/abstract_io.rb,
lib/childprocess/unix/process.rb,
lib/childprocess/windows/process.rb,
lib/childprocess/abstract_process.rb,
lib/childprocess/process_spawn_process.rb
Defined Under Namespace
Modules: Unix, Windows
Classes: AbstractIO, AbstractProcess, Error, InvalidEnvironmentVariable, LaunchError, ProcessSpawnProcess, SubclassResponsibility, TimeoutError
Constant Summary
collapse
- VERSION =
'5.1.0'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.logger ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/childprocess.rb', line 28
def logger
return @logger if defined?(@logger) and @logger
@logger = Logger.new($stderr)
@logger.level = $DEBUG ? Logger::DEBUG : Logger::INFO
@logger
end
|
Class Method Details
.arch ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/childprocess.rb', line 105
def arch
@arch ||= (
host_cpu = RbConfig::CONFIG['host_cpu'].downcase
case host_cpu
when /i[3456]86/
if workaround_older_macosx_misreported_cpu?
"x86_64"
else
"i386"
end
when /amd64|x86_64/
"x86_64"
when /ppc|powerpc/
"powerpc"
else
host_cpu
end
)
end
|
.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.
132
133
134
135
136
137
138
|
# File 'lib/childprocess.rb', line 132
def close_on_exec(file)
if file.respond_to?(:close_on_exec=)
file.close_on_exec = true
else
raise Error, "not sure how to set close-on-exec for #{file.inspect} on #{platform_name.inspect}"
end
end
|
.jruby? ⇒ Boolean
53
54
55
|
# File 'lib/childprocess.rb', line 53
def jruby?
RUBY_ENGINE == 'jruby'
end
|
.linux? ⇒ Boolean
49
50
51
|
# File 'lib/childprocess.rb', line 49
def linux?
os == :linux
end
|
.new(*args) ⇒ Object
Also known as:
build
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/childprocess.rb', line 16
def new(*args)
case os
when :macosx, :linux, :solaris, :bsd, :cygwin, :aix
Unix::Process.new(*args)
when :windows
Windows::Process.new(*args)
else
raise Error, "unsupported platform #{platform_name.inspect}"
end
end
|
.os ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/childprocess.rb', line 77
def os
return :windows if ENV['FAKE_WINDOWS'] == 'true'
@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|dragonfly/
:bsd
when /aix/
:aix
else
raise Error, "unknown os: #{host_os.inspect}"
end
)
end
|
37
38
39
|
# File 'lib/childprocess.rb', line 37
def platform
os
end
|
41
42
43
|
# File 'lib/childprocess.rb', line 41
def platform_name
@platform_name ||= "#{arch}-#{os}"
end
|
.posix_spawn=(bool) ⇒ Object
Set this to true to enable experimental use of posix_spawn.
73
74
75
|
# File 'lib/childprocess.rb', line 73
def posix_spawn=(bool)
@posix_spawn = bool
end
|
.posix_spawn? ⇒ Boolean
65
66
67
|
# File 'lib/childprocess.rb', line 65
def posix_spawn?
false
end
|
.posix_spawn_chosen_explicitly? ⇒ Boolean
61
62
63
|
# File 'lib/childprocess.rb', line 61
def posix_spawn_chosen_explicitly?
@posix_spawn || %w[1 true].include?(ENV['CHILDPROCESS_POSIX_SPAWN'])
end
|
.unix? ⇒ Boolean
45
46
47
|
# File 'lib/childprocess.rb', line 45
def unix?
!windows?
end
|
.windows? ⇒ Boolean
57
58
59
|
# File 'lib/childprocess.rb', line 57
def windows?
os == :windows
end
|