33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/rundoc/code_command/bash.rb', line 33
def shell(cmd, stdin = nil)
cmd = "(#{cmd}) 2>&1"
msg = "Running: $ '#{cmd}'"
msg << " with stdin: '#{stdin.inspect}'" if stdin && !stdin.empty?
puts msg
result = ""
IO.popen(cmd, "w+") do |io|
io << stdin if stdin
io.close_write
until io.eof?
buffer = io.gets
puts " #{buffer}"
result << sanitize_escape_chars(buffer)
end
end
unless $?.success?
raise "Command `#{@line}` exited with non zero status: #{result}" unless keyword.to_s.include?("fail")
end
result
end
|