execute 0.1.52 → 0.1.54
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cmd.rb +54 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a81a615ca56e62d836536bba6830d919528f28d
|
4
|
+
data.tar.gz: 5c9e5fef10d7dc9ee3525ef034c38036d8b7da86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffa7fbb1f77e5ab512bafc105f5ddc830f860cad7c4acbf5cf83a84f49b91899992e7c7544f3f552da857f716a88b2347db54ac182ac82ae2bd2016e7a82fdf6
|
7
|
+
data.tar.gz: 69c962093a87bf7dbed0ec1a1cc7ecde6d3664449c795b67451ce04f5b69a5fbd29e431640a5cb36a0948714c3fa7d13bd3295de466fb9c4707813307c3f46bf
|
data/lib/cmd.rb
CHANGED
@@ -48,8 +48,9 @@ class CMD < Hash
|
|
48
48
|
end
|
49
49
|
|
50
50
|
puts self[:command] if(self[:echo_command] || self[:debug])
|
51
|
-
|
52
|
-
|
51
|
+
#call_popen
|
52
|
+
call_capture
|
53
|
+
|
53
54
|
if(self[:debug])
|
54
55
|
puts "command: #{self[:command]}"
|
55
56
|
puts "output: #{self[:output]}"
|
@@ -57,7 +58,7 @@ class CMD < Hash
|
|
57
58
|
puts "exit_code: #{self[:exit_code]}"
|
58
59
|
end
|
59
60
|
|
60
|
-
raise TimeoutError.new("
|
61
|
+
raise TimeoutError.new("Command '#{self[:command]}' timed out after #{self[:timeout]} seconds") if(key?(:timed_out) && self[:timeout_raise_error])
|
61
62
|
|
62
63
|
if((self[:exit_code] != 0) && !self[:ignore_exit_code])
|
63
64
|
exception_text = "Exit code: #{self[:exit_code]}"
|
@@ -67,7 +68,7 @@ class CMD < Hash
|
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
70
|
-
def
|
71
|
+
def call_popen
|
71
72
|
begin
|
72
73
|
output = ''
|
73
74
|
error = ''
|
@@ -120,13 +121,57 @@ class CMD < Hash
|
|
120
121
|
self[:exit_code]=1 unless(self[:exit_code].nil? || (self[:exit_code] == 0))
|
121
122
|
end
|
122
123
|
end
|
124
|
+
def call_capture
|
125
|
+
elapsed_time = nil
|
126
|
+
begin
|
127
|
+
if(key?(:timeout))
|
128
|
+
start_time = Time.now
|
129
|
+
Thread.new do
|
130
|
+
while !key?(:exit_code) do
|
131
|
+
sleep(0.1)
|
132
|
+
if((Time.now - start_time).to_f > self[:timeout])
|
133
|
+
self[:timed_out] = true
|
134
|
+
interrupt
|
135
|
+
sleep(0.1)
|
136
|
+
break
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
self[:output] = self[:error] = ''
|
143
|
+
elapsed_time = Benchmark.realtime do
|
144
|
+
self[:output], self[:error], status = Open3.capture3(self[:command])
|
145
|
+
self[:exit_code] = status.to_i
|
146
|
+
end
|
147
|
+
|
148
|
+
raise TimeoutError.new("Command '#{self[:command]}' timed out after #{self[:timeout]} seconds") if(key?(:timed_out) && self[:timeout_raise_error])
|
149
|
+
rescue Exception => e
|
150
|
+
self[:error] = "#{self[:error]}\nException: #{e.to_s}"
|
151
|
+
self[:exit_code]=1 unless(!self[:exit_code].nil? || (self[:exit_code] == 0))
|
152
|
+
ensure
|
153
|
+
self[:elapsed_time] = elapsed_time unless(elapsed_time.nil?)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
def command_pid
|
157
|
+
Sys::ProcTable.ps do |p|
|
158
|
+
if(p.ppid == $$)
|
159
|
+
return self[:pid] = p.pid
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
raise "Failed to find child process for command: '#{self[:command]}'"
|
164
|
+
end
|
123
165
|
def interrupt
|
124
|
-
|
166
|
+
self[:pid] = command_pid unless(key?(:pid))
|
167
|
+
raise "Do not have a process id for #{self[:pid]}" unless(key?(:pid))
|
168
|
+
processes = get_child_processes(self[:pid])
|
125
169
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
170
|
+
Process.kill(self[:timeout_signal],self[:pid])
|
171
|
+
sleep(0.1)
|
172
|
+
processes.each { |p| Process.kill(self[:timeout_signal],p.pid) unless(Sys::ProcTable.ps(p.pid).nil?) }
|
173
|
+
#
|
174
|
+
#Process.waitpid(self[:pid]) unless(Sys::ProcTable.ps(self[:pid]).nil?)
|
130
175
|
end
|
131
176
|
def get_child_processes(pid)
|
132
177
|
processes = []
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: execute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.54
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Marshall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|