Class: IO
- Inherits:
-
Object
- Object
- IO
- Defined in:
- lib/branch_io_cli/core_ext/io.rb
Instance Method Summary collapse
-
#log_command(command) ⇒ Object
Report the command.
Instance Method Details
#log_command(command) ⇒ Object
Report the command. Execute the command, capture stdout and stderr and report line by line. Report the exit status at the end in case of error. Returns a Process::Status object.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/branch_io_cli/core_ext/io.rb', line 11 def log_command(command) command = command.map(&:to_s).map(&:shellescape).join(" ") if command.kind_of? Array write "$ #{command}\n\n" Open3.popen2e(command) do |stdin, output, thread| # output is stdout and stderr merged while (line = output.gets) puts line end status = thread.value if status == 0 write "Success.\n\n" else write "#{status}\n\n" end return status end end |