Module: Bake::Gem::Shell
- Included in:
- Helper
- Defined in:
- lib/bake/gem/shell.rb
Instance Method Summary collapse
- #execute(*arguments, **options) ⇒ Object
- #readlines(*arguments, **options) ⇒ Object
- #system(*arguments, **options) ⇒ Object
Instance Method Details
#execute(*arguments, **options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bake/gem/shell.rb', line 29 def execute(*arguments, **) Console::Event::Spawn.for(*arguments, **).emit(self) IO.pipe do |input, output| pid = Process.spawn(*arguments, out: output, **) output.close begin return yield(input) ensure pid, status = Process.wait2(pid) unless status.success? raise "Failed to execute #{arguments}: #{status}!" end end end end |
#readlines(*arguments, **options) ⇒ Object
48 49 50 51 52 |
# File 'lib/bake/gem/shell.rb', line 48 def readlines(*arguments, **) execute(*arguments, **) do |output| return output.readlines end end |
#system(*arguments, **options) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bake/gem/shell.rb', line 12 def system(*arguments, **) Console::Event::Spawn.for(*arguments, **).emit(self) begin pid = Process.spawn(*arguments, **) return yield if block_given? ensure pid, status = Process.wait2(pid) if pid unless status.success? raise "Failed to execute #{arguments}: #{status}!" end return true end end |