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.
:command: [String] a shell command to execute and report
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/branch_io_cli/core_ext/io.rb', line 10 def log_command(command) 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 |