Class: Nanoc::Extra::Piper Private
- Inherits:
-
Object
- Object
- Nanoc::Extra::Piper
- Defined in:
- lib/nanoc/extra/piper.rb
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.
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
-
#initialize(stdout: $stdout, stderr: $stderr) ⇒ Piper
constructor
private
A new instance of Piper.
- #run(cmd, input) ⇒ Object private
Constructor Details
#initialize(stdout: $stdout, stderr: $stderr) ⇒ Piper
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 a new instance of Piper.
19 20 21 22 |
# File 'lib/nanoc/extra/piper.rb', line 19 def initialize(stdout: $stdout, stderr: $stderr) @stdout = stdout @stderr = stderr end |
Instance Method Details
#run(cmd, input) ⇒ Object
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.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nanoc/extra/piper.rb', line 27 def run(cmd, input) Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thr| stdout_thread = Thread.new { @stdout << stdout.read } stderr_thread = Thread.new { @stderr << stderr.read } if input stdin << input end stdin.close stdout_thread.join stderr_thread.join exit_status = wait_thr.value unless exit_status.success? raise Error.new(cmd, exit_status.to_i) end end end |