execute 0.1.37 → 0.1.38
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.
- checksums.yaml +4 -4
- data/lib/cmd.rb +21 -4
- data/lib/timeout_error.rb +5 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e53805a153153e7e3725988c6a5996c39a0bf8f
|
4
|
+
data.tar.gz: ad3c028e120da725a0107b02f58f79e376a0f49e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36063ba89c1baeba1689619cd691c34acf236da671c71dae63745f89fbbdc408d05b6ca6f3f68e8b7ef67fca3e343abe913cd46ed476da0dc626dcf5d87de6ee
|
7
|
+
data.tar.gz: 5e78c0d9cb7304b976a22f3bee9250b3639be08dcd24da132811505ac6b45cfc6540197062107b691a2a3fc179387a2eca77101edd9cbc42354ba2b5fd13b963
|
data/lib/cmd.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'open3'
|
2
2
|
require 'sys/proctable'
|
3
|
+
require_relative 'timeout_error.rb'
|
3
4
|
|
4
5
|
class CMD < Hash
|
5
6
|
private
|
@@ -43,6 +44,8 @@ class CMD < Hash
|
|
43
44
|
exception_text = "#{exception_text}\nOutput: '#{self[:output]}'"
|
44
45
|
raise StandardError.new(exception_text)
|
45
46
|
end
|
47
|
+
|
48
|
+
raise TimedOutError.new(self[:command], self[:timeout]) if(key?(:timed_out))
|
46
49
|
end
|
47
50
|
|
48
51
|
def system
|
@@ -54,9 +57,23 @@ class CMD < Hash
|
|
54
57
|
|
55
58
|
Open3.popen3(self[:command]) do |stdin, stdout, stderr, wait_thr|
|
56
59
|
self[:pid] = wait_thr.pid
|
60
|
+
|
61
|
+
if(key?(:timeout))
|
62
|
+
start_time = Time.now
|
63
|
+
Thread.new do
|
64
|
+
while wait_thr.alive? do
|
65
|
+
sleep(0.1)
|
66
|
+
if((Time.now - start_time).to_f > self[:timeout])
|
67
|
+
self[:timed_out] = true
|
68
|
+
wait_thr.kill
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
57
74
|
{:output => stdout,:error => stderr}.each do |key, stream|
|
58
75
|
Thread.new do
|
59
|
-
while wait_thr.alive? do
|
76
|
+
while wait_thr.alive? && !key?(:timed_out) do
|
60
77
|
if(!(char = stream.getc).nil?)
|
61
78
|
case key
|
62
79
|
when :output
|
@@ -75,9 +92,9 @@ class CMD < Hash
|
|
75
92
|
|
76
93
|
wait_thr.join
|
77
94
|
|
78
|
-
self[:output] = output unless(output.empty?)
|
79
|
-
|
80
|
-
self[:exit_code] = wait_thr.value.to_i
|
95
|
+
self[:output] = output unless(output.empty?)
|
96
|
+
self[:error] = error unless(error.empty?)
|
97
|
+
self[:exit_code] = wait_thr.value.to_i
|
81
98
|
end
|
82
99
|
rescue Exception => e
|
83
100
|
self[:error] = "#{self[:error]}\nException: #{e.to_s}"
|
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.38
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Marshall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- README.md
|
91
91
|
- lib/cmd.rb
|
92
92
|
- lib/cmd_windows.rb
|
93
|
+
- lib/timeout_error.rb
|
93
94
|
homepage: http://rubygems.org/gems/execute
|
94
95
|
licenses:
|
95
96
|
- Apache 2.0
|