Class: Packer::Runner
- Inherits:
-
Object
show all
- Defined in:
- lib/packer/runner.rb
Defined Under Namespace
Classes: CommandExecutionError
Class Method Summary
collapse
Class Method Details
.exec!(*args) ⇒ Object
42
43
44
45
46
|
# File 'lib/packer/runner.rb', line 42
def self.exec!(*args)
cmd = Shellwords.shelljoin(args.flatten)
logger.debug "Exec'ing: #{cmd}, in: #{Dir.pwd}"
Kernel.exec cmd
end
|
.run!(*args, quiet: false) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/packer/runner.rb', line 9
def self.run!(*args, quiet: false)
cmd = Shellwords.shelljoin(args.flatten)
status = 0
stdout = ''
stderr = ''
if quiet
stdout, stderr, status = Open3.capture3(cmd)
else
Open3.popen3(cmd) do |std_in, std_out, std_err, thread|
Thread.new do
until (raw = std_out.getc).nil? do
stdout << raw
$stdout.write "#{raw}"
end
end
Thread.new do
until (raw_line = std_err.gets).nil? do
stderr << raw_line
end
end
thread.join status = thread.value
end
end
raise CommandExecutionError.new(stderr) unless status == 0
stdout
end
|