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
33
34
35
36
37
|
# File 'lib/packer/runner.rb', line 33
def self.exec!(*args)
cmd = Shellwords.shelljoin(args.flatten)
logger.debug "Exec'ing: #{cmd}, in: #{Dir.pwd}"
Kernel.exec cmd
end
|
.pty(cmd, &block) ⇒ Object
39
40
41
42
|
# File 'lib/packer/runner.rb', line 39
def self.pty(cmd, &block)
PTY.spawn(cmd, &block)
$?.exitstatus
end
|
.run!(*args, quiet: false) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/packer/runner.rb', line 10
def self.run!(*args, quiet: false)
cmd = Shellwords.shelljoin(args.flatten)
status = 0
stdout = ''
stderr = ''
if quiet
stdout, stderr, status = Open3.capture3(cmd)
else
status = pty(cmd) do |r,w,pid|
while !r.eof?
c = r.getc
stdout << c
$stdout.write "#{c}"
end
Process.wait(pid)
end
end
raise CommandExecutionError.new(stderr) unless status == 0
stdout
end
|