P
Payton Swick
How does one check a pipe (created using IO.popen) to see if there is
input waiting without using IO#eof or reading from the pipe? Doing
either of these seems to hang forever if the pipe is empty.
Here's an example:
require 'timeout'
IO.popen("cat", "r+") do |pipe|
# pipe.puts "hello world" # Uncomment this to prevent hang below.
Timeout::timeout(2) do
if not pipe.eof? # This will hang if the pipe is empty.
p pipe.getc
end
end
end
-Payton
input waiting without using IO#eof or reading from the pipe? Doing
either of these seems to hang forever if the pipe is empty.
Here's an example:
require 'timeout'
IO.popen("cat", "r+") do |pipe|
# pipe.puts "hello world" # Uncomment this to prevent hang below.
Timeout::timeout(2) do
if not pipe.eof? # This will hang if the pipe is empty.
p pipe.getc
end
end
end
-Payton