Created
January 27, 2009 12:19
-
-
Save fsvehla/53315 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start_time = timestamp | |
open = true | |
status = Open4.popen4(command) do |pid, _, out, err| | |
while(open) | |
elapsed = (timestamp - start_time) | |
if elapsed > CommandTimeout | |
out.close rescue puts "out close err" | |
err.close rescue puts "err close err" | |
# quite hackish, but works. | |
Process.kill(15, pid) rescue puts $!.inspect | |
raise ConversionError.new( | |
'Timeout while converting after %01.3f seconds (Timeout %01.3f).' % [ | |
elapsed, | |
CommandTimeout | |
]) | |
end | |
if ready = IO.select([out], [err], nil, (1.0 / 24)) | |
if ready.flatten.include?(out) | |
begin | |
while(data = out.readpartial(4096)) | |
out += data | |
end | |
rescue EOFError => e | |
open = false | |
end | |
end | |
if ready.flatten.include?(err) | |
begin | |
while(data = err.readpartial(4096)) | |
err_output += data | |
end | |
rescue EOFError => e | |
open = false | |
end | |
end | |
else | |
# No data available right now or we've read all of it. | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment