execute 0.1.27 → 0.1.28

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cmd.rb +29 -43
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8092c81d49b0155e507821497351080cd849e2fd
4
- data.tar.gz: a7d996ca8087684e3011f54eb7ce5c44b66fc8ad
3
+ metadata.gz: cbf8302ef5762c5a88bd8031c6eeec431e3f59b0
4
+ data.tar.gz: a8e0bceb270da38b54131ebc1e3d615f3b0df656
5
5
  SHA512:
6
- metadata.gz: 48009fb0c04c7f0f624444053bb8fc16d80204d5a9d041b2dbe5d4e834f05d4f85d9c8f6d0d3848d6df00428b1634e4f73ce351c89cbae2256e2d65d6e941566
7
- data.tar.gz: 0701ebd759826e07725561b604230e45728f57c33acff06294c639e571bc94e2bd97f912f0c021189568d3b9643695e66779aabb5a52ef1d14128e9914774a5b
6
+ metadata.gz: 8edb50d16bb521a208c9a4db542fe715adcf38036472b9dd307ea59a61a8bc3edeea85a03612a51fcf187e46e2df04fb5cf684ddb278014f5ba7101c1901a9dc
7
+ data.tar.gz: 7f59512206dff638b3109c278f0142ff5317d64ac66a4cdf27a31a0721c83a45d5df4f15c8d6f0c6ff2153c49c9cb947702cd97800bdb9d3c2621dc588c0767c
data/lib/cmd.rb CHANGED
@@ -22,44 +22,44 @@ class CMD < Hash
22
22
  end
23
23
 
24
24
  def execute
25
+ puts self[:command] if(self[:echo_command] || self[:debug])
26
+ system
27
+
28
+ if(self[:debug])
29
+ puts "command: #{self[:command]}" if(self[:quiet])
30
+ puts "output: #{self[:output]}"
31
+ puts "error: #{self[:error]}"
32
+ puts "exit_code: #{self[:exit_code]}"
33
+ end
34
+
35
+ if((self[:exit_code] != 0) && !self[:ignore_exit_code])
36
+ exception_text = "Exit code: #{self[:exit_code]}"
37
+ exception_text = "#{exception_text}\n#{self[:error]}"
38
+ exception_text = "#{exception_text}\n#{self[:output]}" if(self[:error].empty?)
39
+ raise exception_text
40
+ end
41
+ end
42
+
43
+ def system
25
44
  begin
26
- puts self[:command] if(self[:echo_command] || self[:debug])
27
-
28
- output = {output: [], error: [] }
45
+ output = {output: [], error: [] }
29
46
  Open3.popen3(self[:command]) do |stdin, stdout, stderr, wait_thr|
30
47
  self[:pid] = wait_thr.pid
31
48
  {:output => stdout,:error => stderr}.each do |key, stream|
32
- Thread.new do
33
- while wait_thr.alive? do
34
- if(!(char = stream.getc).nil?)
35
- output[key] << char
49
+ Thread.new do
50
+ while wait_thr.alive? do
51
+ if(!(char = stream.getc).nil?)
52
+ output[key] << char
36
53
  putc char if(self[:echo_output])
37
- else
38
- sleep(0.1)
54
+ else
55
+ sleep(0.1)
39
56
  end
40
- end
57
+ end
41
58
  end
42
59
  end
43
-
44
- # $stdin.gets reads from the console
45
- # stdin.puts writes to child process
46
- #
47
- # while thread.alive? means that we keep on
48
- # reading input until the child process ends
49
- #Thread.new do
50
- # while wait_thr.alive? do
51
- # #begin
52
- # puts "HERE"
53
- # c = STDIN.gets
54
- # puts "char: #{c}"
55
- # stdin.puts c
56
- # #rescue Interrupt, Errno::EINTR
57
- # # exit(1)
58
- # #end
59
- # end
60
- #end
61
-
60
+
62
61
  wait_thr.join
62
+
63
63
  self[:output] = output[:output].join unless(output[:output].empty?)
64
64
  self[:error] = output[:error].join unless(output[:error].empty?)
65
65
  self[:exit_code] = wait_thr.value.to_i
@@ -68,19 +68,5 @@ class CMD < Hash
68
68
  self[:error] = "#{self[:error]}\nException: #{e.to_s}"
69
69
  self[:exit_code]=1 unless(self[:exit_code].nil? || (self[:exit_code] == 0))
70
70
  end
71
-
72
- if(self[:debug])
73
- puts "command: #{self[:command]}" if(self[:quiet])
74
- puts "output: #{self[:output]}"
75
- puts "error: #{self[:error]}"
76
- puts "exit_code: #{self[:exit_code]}"
77
- end
78
-
79
- if((self[:exit_code] != 0) && !self[:ignore_exit_code])
80
- exception_text = "Exit code: #{self[:exit_code]}"
81
- exception_text = "#{exception_text}\n#{self[:error]}"
82
- exception_text = "#{exception_text}\n#{self[:output]}" if(self[:error].empty?)
83
- raise exception_text
84
- end
85
71
  end
86
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: execute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.27
4
+ version: 0.1.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Marshall