Class: Rtimeout
- Inherits:
-
Object
- Object
- Rtimeout
- Defined in:
- lib/rtimeout.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(timeout, command) ⇒ Rtimeout
constructor
A new instance of Rtimeout.
- #read ⇒ Object
Constructor Details
#initialize(timeout, command) ⇒ Rtimeout
Returns a new instance of Rtimeout.
5 6 7 8 9 |
# File 'lib/rtimeout.rb', line 5 def initialize(timeout, command) @timeout = timeout.to_i @command = command @pid, _, @io, _ = Open4.popen4(command) end |
Class Method Details
.read(timeout, command) ⇒ Object
24 25 26 |
# File 'lib/rtimeout.rb', line 24 def self.read(timeout, command) new(timeout, command).read end |
Instance Method Details
#read ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rtimeout.rb', line 11 def read while result = IO.select([@io], nil, nil, @timeout) out = @io.read(1) break if out.nil? $stdout.print out end if result.nil? system "kill -9 #{@pid}" $stderr.puts "rtimeout: Command `#{@command}` timed out." end end |