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 = ShellTastic::Timer) ⇒ Array, Hash
A wrapper around popen4.
Methods included from Utils
Class Method Details
.popen(command, timer = ShellTastic::Timer) ⇒ Array, Hash
A wrapper around popen4
- { :output, :pid, :error, :start, :stop, :total_time, :exitstatus }
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/shelltastic/command_io.rb', line 15 def popen(command, timer=ShellTastic::Timer) string_nil_or_blank?(command) command_results = {} begin start = timer.start return_code = Open4::popen4(command) do |pid, stdin, stdout, stderr| command_results.store(:output,stdout.read.strip) command_results.store(:pid,pid) command_results.store(:error,stderr.read.strip) stdin.close end stop = timer.stop total_time = timer.total_time command_results.merge!(start: start, stop: stop, command: command, total_time: total_time, exitstatus: return_code.exitstatus) rescue Errno::ENOENT => e raise ShellTastic::CommandException.new("Shell command #{command} failed with status #{$?} and ERROR: #{e.}") end command_results end |