18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/xccache/core/sh.rb', line 18
def run(*args, env: nil, **options)
cmd = args.join(" ")
UI.message("$ #{cmd}".cyan.dark) if config.verbose? && options[:log_cmd] != false
return system(cmd) || (raise GeneralError, "Command '#{cmd}' failed") unless options[:capture]
out, err = [], []
popen3_args = env ? [env, cmd] : [cmd]
Open3.popen3(*popen3_args) do |_stdin, stdout, stderr, wait_thr|
stdout_thread = Thread.new { stdout.each { |l| out << l } }
stderr_thread = Thread.new { stderr.each { |l| err << l } }
[stdout_thread, stderr_thread].each(&:join)
result = wait_thr.value
result.exitstatus
raise ExecError, "Command '#{cmd}' failed with status: #{result.exitstatus}" unless result.success?
end
[out.join("\n"), err.join("\n")]
end
|