cgi-spa 0.3.4 → 0.4.0
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/cgi-spa.gemspec +1 -1
- data/lib/cgi-spa/html-methods.rb +40 -0
- data/lib/cgi-spa/version.rb +2 -2
- metadata +3 -3
data/cgi-spa.gemspec
CHANGED
data/lib/cgi-spa/html-methods.rb
CHANGED
@@ -23,3 +23,43 @@ def $x.script!(text)
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
# execute a system command, echoing stdin, stdout, and stderr
|
28
|
+
def $x.system!(command, opts={})
|
29
|
+
require 'open3'
|
30
|
+
output_class = opts[:class] || {}
|
31
|
+
stdin = output_class[:stdin] || 'stdin'
|
32
|
+
stdout = output_class[:stdout] || 'stdout'
|
33
|
+
stderr = output_class[:stderr] || 'stderr'
|
34
|
+
|
35
|
+
$x.pre command, :class=>stdin unless opts[:echo] == false
|
36
|
+
|
37
|
+
semaphore = Mutex.new
|
38
|
+
Open3.popen3(command) do |pin, pout, perr|
|
39
|
+
[
|
40
|
+
Thread.new do
|
41
|
+
until pout.eof?
|
42
|
+
out_line = pout.readline.chomp
|
43
|
+
semaphore.synchronize { $x.pre out_line, :class=>stdout }
|
44
|
+
end
|
45
|
+
end,
|
46
|
+
|
47
|
+
Thread.new do
|
48
|
+
until perr.eof?
|
49
|
+
err_line = perr.readline.chomp
|
50
|
+
semaphore.synchronize { $x.pre err_line, :class=>stderr }
|
51
|
+
end
|
52
|
+
end,
|
53
|
+
|
54
|
+
Thread.new do
|
55
|
+
if opts[:stdin].respond_to? :read
|
56
|
+
require 'fileutils'
|
57
|
+
FileUtils.copy_stream opts[:stdin], pin
|
58
|
+
elsif opts[:stdin]
|
59
|
+
pin.write opts[:stdin].to_s
|
60
|
+
end
|
61
|
+
pin.close
|
62
|
+
end
|
63
|
+
].each {|thread| thread.join}
|
64
|
+
end
|
65
|
+
end
|
data/lib/cgi-spa/version.rb
CHANGED
metadata
CHANGED