execute 0.1.60 → 0.1.62
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 +23 -29
- 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: c03b6064b5618dfe687c78adc1aafa012c1442ca
|
4
|
+
data.tar.gz: a6af42c420a9a50f1c35e9e3fbe576aa9cefba23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2dbd1f768929fb92cdd344bc8d57c733e79a2ad964b30c450116a3458e3f1e6c1356894561dca5cb1fdf988199767d8d34ea67ec1a43ca6e49b81b195add165
|
7
|
+
data.tar.gz: 306ae3dda19c7ca8bcfc984963918385c443d7808f27b7687428258cbe0b33b234c831a4f406cf7efc2d760919fca4db43b053fe5f229566f54a37afc7445f1f
|
data/lib/cmd.rb
CHANGED
@@ -49,8 +49,8 @@ class CMD < Hash
|
|
49
49
|
end
|
50
50
|
|
51
51
|
puts self[:command] if(self[:echo_command] || self[:debug])
|
52
|
-
call_popen
|
53
|
-
|
52
|
+
self[:elapsed_time] = Benchmark.realtime { call_popen }
|
53
|
+
#self[:elapsed_time] = Benchmark.realtime { call_capture }
|
54
54
|
|
55
55
|
if(self[:debug])
|
56
56
|
puts "command: #{self[:command]}"
|
@@ -73,7 +73,6 @@ class CMD < Hash
|
|
73
73
|
begin
|
74
74
|
output = ''
|
75
75
|
error = ''
|
76
|
-
Thread.abort_on_exception = true
|
77
76
|
mutex = Mutex.new
|
78
77
|
|
79
78
|
Open3.popen3(self[:command]) do |stdin, stdout, stderr, wait_thr|
|
@@ -83,11 +82,10 @@ class CMD < Hash
|
|
83
82
|
start_time = Time.now
|
84
83
|
Thread.new do
|
85
84
|
while wait_thr.alive? do
|
86
|
-
sleep(0.1)
|
87
85
|
if((Time.now - start_time).to_f > self[:timeout])
|
88
86
|
self[:timed_out] = true
|
89
87
|
interrupt
|
90
|
-
|
88
|
+
Thread.stop
|
91
89
|
end
|
92
90
|
end
|
93
91
|
end
|
@@ -95,18 +93,22 @@ class CMD < Hash
|
|
95
93
|
|
96
94
|
{:output => stdout,:error => stderr}.each do |key, stream|
|
97
95
|
Thread.new do
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
96
|
+
begin
|
97
|
+
while wait_thr.alive? && !key?(:timed_out) && !@stop_threads do
|
98
|
+
unless(stream.closed?)
|
99
|
+
unless((char = stream.getc).nil?)
|
100
|
+
case key
|
101
|
+
when :output
|
102
|
+
output << char
|
103
|
+
putc char if(self[:echo_output])
|
104
|
+
when :error
|
105
|
+
error << char
|
106
|
+
end
|
107
|
+
end
|
106
108
|
end
|
107
|
-
else
|
108
|
-
sleep(0.1)
|
109
109
|
end
|
110
|
+
rescue IOError
|
111
|
+
Thread.stop
|
110
112
|
end
|
111
113
|
end
|
112
114
|
end
|
@@ -117,16 +119,12 @@ class CMD < Hash
|
|
117
119
|
self[:error] = error unless(error.empty?)
|
118
120
|
self[:exit_code] = wait_thr.value.to_i
|
119
121
|
end
|
120
|
-
rescue Interrupt => e
|
121
|
-
interrupt
|
122
|
-
raise e
|
123
122
|
rescue Exception => e
|
124
123
|
self[:error] = "#{self[:error]}\nException: #{e.to_s}"
|
125
124
|
self[:exit_code]=1 unless(self[:exit_code].nil? || (self[:exit_code] == 0))
|
126
125
|
end
|
127
126
|
end
|
128
127
|
def call_capture
|
129
|
-
elapsed_time = nil
|
130
128
|
begin
|
131
129
|
if(key?(:timeout))
|
132
130
|
start_time = Time.now
|
@@ -144,10 +142,8 @@ class CMD < Hash
|
|
144
142
|
end
|
145
143
|
|
146
144
|
self[:output] = self[:error] = ''
|
147
|
-
|
148
|
-
|
149
|
-
self[:exit_code] = status.to_i
|
150
|
-
end
|
145
|
+
self[:output], self[:error], status = Open3.capture3(self[:command])
|
146
|
+
self[:exit_code] = status.to_i
|
151
147
|
|
152
148
|
puts self[:output] if(self[:echo_output] && !self[:output].empty?)
|
153
149
|
|
@@ -155,8 +151,6 @@ class CMD < Hash
|
|
155
151
|
rescue Exception => e
|
156
152
|
self[:error] = "#{self[:error]}\nException: #{e.to_s}"
|
157
153
|
self[:exit_code]=1 unless(!self[:exit_code].nil? || (self[:exit_code] == 0))
|
158
|
-
ensure
|
159
|
-
self[:elapsed_time] = elapsed_time unless(elapsed_time.nil?)
|
160
154
|
end
|
161
155
|
end
|
162
156
|
def command_pid
|
@@ -173,12 +167,12 @@ class CMD < Hash
|
|
173
167
|
raise "Do not have a process id for #{self[:pid]}" unless(key?(:pid))
|
174
168
|
processes = get_child_processes(self[:pid])
|
175
169
|
|
176
|
-
Process.kill(self[:timeout_signal],self[:pid])
|
177
|
-
|
170
|
+
Process.kill(self[:timeout_signal], self[:pid])
|
171
|
+
Process.waitpid(self[:pid]) unless(Sys::ProcTable.ps(self[:pid]).nil?)
|
172
|
+
|
178
173
|
processes.each { |p| Process.kill(self[:timeout_signal],p.pid) unless(Sys::ProcTable.ps(p.pid).nil?) }
|
179
|
-
#
|
180
|
-
#Process.waitpid(self[:pid]) unless(Sys::ProcTable.ps(self[:pid]).nil?)
|
181
174
|
end
|
175
|
+
|
182
176
|
def get_child_processes(pid)
|
183
177
|
processes = []
|
184
178
|
Sys::ProcTable.ps do |p|
|
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.62
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|