Class: R10K::Util::Subprocess Private
- Inherits:
-
Object
- Object
- R10K::Util::Subprocess
- Includes:
- Logging
- Defined in:
- lib/r10k/util/subprocess.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The subprocess namespace implements an interface similar to childprocess. The interface has been simplified to make it easier to use and does not depend on native code.
Defined Under Namespace
Modules: POSIX, Windows Classes: IO, Result, Runner, SubprocessError
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
- #argv ⇒ Object readonly private
-
#cwd ⇒ String
The directory to be used as the cwd when executing the command.
- #logger ⇒ Object writeonly private
-
#raise_on_fail ⇒ true, false
Determine whether #execute raises an error when the command exits with a non-zero exit status.
Class Method Summary collapse
-
.runner ⇒ Class < R10K::Util::Subprocess::Runner]
private
Class < R10K::Util::Subprocess::Runner].
Instance Method Summary collapse
-
#execute ⇒ R10K::Util::Subprocess::Result
Execute the given command and return the result of evaluation.
-
#initialize(argv) ⇒ Subprocess
constructor
private
Prepare the subprocess invocation.
Methods included from Logging
formatter, included, level, level=, levels, #logger, #logger_name, outputter, parse_level
Constructor Details
#initialize(argv) ⇒ Subprocess
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prepare the subprocess invocation.
56 57 58 59 60 |
# File 'lib/r10k/util/subprocess.rb', line 56 def initialize(argv) @argv = argv @raise_on_fail = false end |
Instance Attribute Details
#argv ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 |
# File 'lib/r10k/util/subprocess.rb', line 35 def argv @argv end |
#cwd ⇒ String
Returns The directory to be used as the cwd when executing the command.
46 47 48 |
# File 'lib/r10k/util/subprocess.rb', line 46 def cwd @cwd end |
#logger=(value) ⇒ Object (writeonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
51 52 53 |
# File 'lib/r10k/util/subprocess.rb', line 51 def logger=(value) @logger = value end |
#raise_on_fail ⇒ true, false
Determine whether #execute raises an error when the command exits with a non-zero exit status.
41 42 43 |
# File 'lib/r10k/util/subprocess.rb', line 41 def raise_on_fail @raise_on_fail end |
Class Method Details
.runner ⇒ Class < R10K::Util::Subprocess::Runner]
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Class < R10K::Util::Subprocess::Runner].
23 24 25 26 27 28 29 |
# File 'lib/r10k/util/subprocess.rb', line 23 def self.runner if R10K::Util::Platform.windows? R10K::Util::Subprocess::Windows::Runner else R10K::Util::Subprocess::POSIX::Runner end end |
Instance Method Details
#execute ⇒ R10K::Util::Subprocess::Result
Execute the given command and return the result of evaluation.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/r10k/util/subprocess.rb', line 68 def execute subprocess = self.class.runner.new(@argv) subprocess.cwd = @cwd if @cwd logmsg = "Execute: #{@argv.join(' ')}" logmsg << "(cwd: #{@cwd})" if @cwd logger.debug1 logmsg subprocess.run result = subprocess.result 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 |