Class: ShellTastic::IO
- Inherits:
-
Object
- Object
- ShellTastic::IO
- Extended by:
- Utils
- Defined in:
- lib/shelltastic/command_io.rb
Class Method Summary collapse
-
.popen(command, timer, formatter) ⇒ Hash
A wrapper around popen4.
Methods included from Utils
empty_nil_blank?, string_nil_or_blank!, string_nil_or_blank?
Class Method Details
.popen(command, timer, formatter) ⇒ Hash
A wrapper around popen4
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/shelltastic/command_io.rb', line 19 def popen(command, timer, formatter) string_nil_or_blank! command begin formatter.start = timer.start pid, stdin, stdout, stderr = Open4::popen4(command) stdin.close _, status = Process::waitpid2 pid error = stderr.read.strip formatter.build(command: command, output: stdout.read.strip, pid: pid, error: string_nil_or_blank?(error) ? false : error, stop: timer.stop, exitstatus: status.exitstatus, total_time: timer.total_time) rescue Errno::ENOENT => e raise ShellTastic::CommandException.new("Shell command #{command} failed with status #{$?} and ERROR: #{e.}") end formatter.inspect end |