Class: R10K::Util::Subprocess
- Inherits:
-
Object
- Object
- R10K::Util::Subprocess
- Includes:
- Logging
- Defined in:
- lib/r10k/util/subprocess.rb
Overview
The subprocess namespace implements a subset of childprocess. It has three # main differences.
1. child processes invoke setsid()
2. there are no dependencies on C extensions (ffi)
3. it only support unixy systems.
Defined Under Namespace
Classes: IO, Result, Runner, SubprocessError
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#cwd ⇒ Object
Returns the value of attribute cwd.
-
#logger ⇒ Object
writeonly
Sets the attribute logger.
-
#raise_on_fail ⇒ Object
Returns the value of attribute raise_on_fail.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(argv) ⇒ Subprocess
constructor
A new instance of Subprocess.
Methods included from Logging
formatter, included, level, level=, levels, #logger, #logger_name, outputter, parse_level
Constructor Details
#initialize(argv) ⇒ Subprocess
Returns a new instance of Subprocess.
26 27 28 29 30 |
# File 'lib/r10k/util/subprocess.rb', line 26 def initialize(argv) @argv = argv @raise_on_fail = false end |
Instance Attribute Details
#cwd ⇒ Object
Returns the value of attribute cwd.
22 23 24 |
# File 'lib/r10k/util/subprocess.rb', line 22 def cwd @cwd end |
#logger=(value) ⇒ Object (writeonly)
Sets the attribute logger
24 25 26 |
# File 'lib/r10k/util/subprocess.rb', line 24 def logger=(value) @logger = value end |
#raise_on_fail ⇒ Object
Returns the value of attribute raise_on_fail.
21 22 23 |
# File 'lib/r10k/util/subprocess.rb', line 21 def raise_on_fail @raise_on_fail end |
Instance Method Details
#execute ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/r10k/util/subprocess.rb', line 32 def execute subprocess = R10K::Util::Subprocess::Runner.new(@argv) subprocess.cwd = @cwd stdout_r, stdout_w = attach_pipe(subprocess.io, :stdout, :reader) stderr_r, stderr_w = attach_pipe(subprocess.io, :stderr, :reader) logmsg = "Execute: #{@argv.join(' ')}" logmsg << "(cwd: #{@cwd})" if @cwd logger.debug1 logmsg subprocess.start stdout_w.close stderr_w.close subprocess.wait stdout = stdout_r.read stderr = stderr_r.read result = Result.new(@argv, stdout, stderr, subprocess.exit_code) logger.debug2 "[#{result.cmd}] STDOUT: #{result.stdout.chomp}" unless result.stdout.empty? logger.debug2 "[#{result.cmd}] STDERR: #{result.stderr.chomp}" unless result.stderr.empty? if @raise_on_fail and subprocess.crashed? raise SubprocessError.new(:result => result) end result end |