execute 0.1.18 → 0.1.19
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 +24 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88173eecd2af8a6411804f35b30ba95decc9e9bf
|
4
|
+
data.tar.gz: 7ff1a4bb4dbe8b0f1f79d42be784806652d03026
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
44
|
-
|
45
|
-
|
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
|