simple-spawn 0.1.0 → 0.1.1
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.
- data/lib/simple/spawn.rb +30 -15
- data/simple-spawn.gemspec +1 -1
- metadata +1 -1
data/lib/simple/spawn.rb
CHANGED
@@ -11,8 +11,8 @@ module Simple
|
|
11
11
|
tmp_out = $stdout
|
12
12
|
pipe = []
|
13
13
|
|
14
|
-
commands.each_with_index do |
|
15
|
-
program, *args = Shellwords.shellsplit(
|
14
|
+
commands.each_with_index do |cmd, index|
|
15
|
+
program, *args = Shellwords.shellsplit(cmd)
|
16
16
|
|
17
17
|
if index+1 < commands.size
|
18
18
|
pipe = IO.pipe
|
@@ -21,7 +21,7 @@ module Simple
|
|
21
21
|
tmp_out = $stdout
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
Spawner.new(program, *args, tmp_out, tmp_in).exec!
|
25
25
|
|
26
26
|
tmp_out.close unless tmp_out == $stdout
|
27
27
|
tmp_in.close unless tmp_in == $stdin
|
@@ -35,20 +35,35 @@ module Simple
|
|
35
35
|
line.scan( /([^"'|]+)|["']([^"']+)["']/ ).flatten.compact
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
|
-
fork {
|
40
|
-
unless tmp_out == $stdout
|
41
|
-
$stdout.reopen(tmp_out)
|
42
|
-
tmp_out.close
|
43
|
-
end
|
38
|
+
class Spawner
|
44
39
|
|
45
|
-
|
46
|
-
$stdin.reopen(tmp_in)
|
47
|
-
tmp_in.close
|
48
|
-
end
|
40
|
+
attr_reader :program, :args, :tmp_out, :tmp_in
|
49
41
|
|
50
|
-
|
51
|
-
|
42
|
+
def initialize program, *args, tmp_out, tmp_in
|
43
|
+
@tmp_out = tmp_out
|
44
|
+
@tmp_in = tmp_in
|
45
|
+
@program = program
|
46
|
+
@args = *args
|
47
|
+
end
|
48
|
+
|
49
|
+
def exec!
|
50
|
+
fork {
|
51
|
+
close_out unless tmp_out == $stdout
|
52
|
+
close_in unless tmp_in == $stdin
|
53
|
+
exec program, *args
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def close_out
|
60
|
+
$stdout.reopen(tmp_out)
|
61
|
+
tmp_out.close
|
62
|
+
end
|
63
|
+
def close_in
|
64
|
+
$stdin.reopen(tmp_in)
|
65
|
+
tmp_in.close
|
66
|
+
end
|
52
67
|
end
|
53
68
|
end
|
54
69
|
end
|
data/simple-spawn.gemspec
CHANGED