execute 0.1.18 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cmd.rb +24 -4
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78f796b184fcec8592b83bf5b532eea64764d8a3
4
- data.tar.gz: 4cf6927fea0ffbe714a66f1d1e3e87dade6bd382
3
+ metadata.gz: 88173eecd2af8a6411804f35b30ba95decc9e9bf
4
+ data.tar.gz: 7ff1a4bb4dbe8b0f1f79d42be784806652d03026
5
5
  SHA512:
6
- metadata.gz: 4ad7ca5651ac17ba94d3e4c555ef1c09db0f10bd01eec51f189621dcf71b228ec45e488c0e663adec39993860b6daa11f06e34c6730154fc2e2daff9ad319b48
7
- data.tar.gz: 64d76b18235603623de50999f6cacf0ffe9db02801549d7978b9add82ed4d64a09af805ab52a4273baa4d286514e3bd5adc2a953d02999980b5b2ce52ef4a285
6
+ metadata.gz: b56fc793f61b4f1559b2b03bbac688a60341b17afa77a6cf19b9b9786e9fe090822fed1dfd9e5d204f7daa56232c3dad3969f4721805844dfdb6ba3f75f75180
7
+ data.tar.gz: 4d96f0d03804375abc973f1528de703e47060ae4825f9e239f210cf83d4bf8698ecab1a2a9ade5d8b0bcc29b02c2372bfcf017398388d5a17e294ffe95a35038
data/lib/cmd.rb CHANGED
@@ -37,15 +37,35 @@ class CMD < Hash
37
37
  puts cmd if(hash[:echo_command] || hash[:debug])
38
38
 
39
39
  output = {output: [], error: [] }
40
- Open3.popen3(cmd, stdin=STDIN) do |stdin, stdout, stderr, wait_thr|
40
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
41
41
  {:output => stdout,:error => stderr}.each do |key, stream|
42
42
  Thread.new do
43
- until(char = stream.getc).nil? do
44
- output[key] << char
45
- putc char if(hash[:echo_output])
43
+ while wait_thr.alive? do
44
+ if(!(char = stream.getc).nil?)
45
+ output[key] << char
46
+ putc char if(hash[:echo_output])
47
+ else
48
+ sleep(0.1)
49
+ end
46
50
  end
47
51
  end
48
52
  end
53
+
54
+ # $stdin.gets reads from the console
55
+ # stdin.puts writes to child process
56
+ #
57
+ # while thread.alive? means that we keep on
58
+ # reading input until the child process ends
59
+ Thread.new do
60
+ while wait_thr.alive? do
61
+ begin
62
+ stdin.puts $stdin.gets while wait_thr.alive?
63
+ rescue Interrupt, Errno::EINTR
64
+ exit(1)
65
+ end
66
+ end
67
+ end
68
+
49
69
  wait_thr.join
50
70
  hash[:output] = output[:output].join
51
71
  hash[:error] = output[:error].join
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.18
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Marshall