childprocess 0.2.9 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +4 -1
- data/lib/childprocess/jruby/process.rb +3 -2
- data/lib/childprocess/unix/fork_exec_process.rb +1 -1
- data/lib/childprocess/unix/posix_spawn_process.rb +3 -1
- data/lib/childprocess/version.rb +1 -1
- data/lib/childprocess/windows/process_builder.rb +5 -5
- data/spec/childprocess_spec.rb +21 -2
- metadata +5 -5
data/README.md
CHANGED
@@ -20,8 +20,11 @@ process.io.inherit!
|
|
20
20
|
# ...or pass an IO
|
21
21
|
process.io.stdout = Tempfile.new("child-output")
|
22
22
|
|
23
|
-
#
|
23
|
+
# modify the environment for the child
|
24
|
+
process.environment["a"] = "b"
|
25
|
+
process.environment["c"] = nil
|
24
26
|
|
27
|
+
# start the process
|
25
28
|
process.start
|
26
29
|
|
27
30
|
# check process status
|
@@ -111,8 +111,9 @@ module ChildProcess
|
|
111
111
|
end
|
112
112
|
|
113
113
|
def set_env(env)
|
114
|
-
ENV.each
|
115
|
-
|
114
|
+
ENV.to_hash.merge(@environment).each do |k,v|
|
115
|
+
env.put(k.to_s, v.to_s) if v
|
116
|
+
end
|
116
117
|
end
|
117
118
|
|
118
119
|
end # Process
|
@@ -100,12 +100,14 @@ module ChildProcess
|
|
100
100
|
class Envp
|
101
101
|
def initialize(env)
|
102
102
|
@ptrs = env.map do |key, val|
|
103
|
+
next if val.nil?
|
104
|
+
|
103
105
|
if key =~ /=|\0/ || val.include?("\0")
|
104
106
|
raise InvalidEnvironmentVariable, "#{key.inspect} => #{val.inspect}"
|
105
107
|
end
|
106
108
|
|
107
109
|
FFI::MemoryPointer.from_string("#{key}=#{val}")
|
108
|
-
end
|
110
|
+
end.compact
|
109
111
|
|
110
112
|
@ptrs << nil
|
111
113
|
end
|
data/lib/childprocess/version.rb
CHANGED
@@ -44,12 +44,12 @@ module ChildProcess
|
|
44
44
|
def create_environment_pointer
|
45
45
|
return unless @environment.kind_of?(Hash) && @environment.any?
|
46
46
|
|
47
|
-
|
48
|
-
strings = ENV.map { |k,v| "#{k}=#{v}\0" }
|
47
|
+
strings = []
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
ENV.to_hash.merge(@environment).each do |key, val|
|
50
|
+
next if val.nil?
|
51
|
+
|
52
|
+
if key.to_s =~ /=|\0/ || val.to_s.include?("\0")
|
53
53
|
raise InvalidEnvironmentVariable, "#{key.inspect} => #{val.inspect}"
|
54
54
|
end
|
55
55
|
|
data/spec/childprocess_spec.rb
CHANGED
@@ -101,6 +101,22 @@ describe ChildProcess do
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
+
it "can unset env vars" do
|
105
|
+
Tempfile.open("env-spec") do |file|
|
106
|
+
ENV['CHILDPROCESS_UNSET'] = '1'
|
107
|
+
process = write_env(file.path)
|
108
|
+
process.environment['CHILDPROCESS_UNSET'] = nil
|
109
|
+
process.start
|
110
|
+
|
111
|
+
process.wait
|
112
|
+
file.rewind
|
113
|
+
|
114
|
+
child_env = eval(file.read)
|
115
|
+
child_env.should_not have_key('CHILDPROCESS_UNSET')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
|
104
120
|
it "passes arguments to the child" do
|
105
121
|
args = ["foo", "bar"]
|
106
122
|
|
@@ -122,11 +138,14 @@ describe ChildProcess do
|
|
122
138
|
process = ruby("print Dir.pwd")
|
123
139
|
process.io.stdout = process.io.stderr = file
|
124
140
|
|
125
|
-
|
141
|
+
Dir.chdir(Dir.tmpdir) do
|
142
|
+
process.start
|
143
|
+
end
|
144
|
+
|
126
145
|
process.wait
|
127
146
|
|
128
147
|
file.rewind
|
129
|
-
file.read.should == Dir.
|
148
|
+
file.read.should == Dir.tmpdir
|
130
149
|
end
|
131
150
|
end
|
132
151
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: childprocess
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jari Bakken
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-01-
|
18
|
+
date: 2012-01-13 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|