Howdy,
I’m trying to use select() with Open3.popen3 on Solaris 8 with ruby 1.6.7.
If it matters ruby was built on Solaris 2.6.
It seems that select() is claiming file descriptors are ready whether or
not they are.
The simple program I’m trying as a test is:
#!/usr/sepp/bin/ruby
require ‘open3’
def run_command
[stdin, out, err] = Open3.popen3(“cat /etc/hosts”)
while not (r=select([out,err])).nil?
yield r.inspect
end
end
run_command { |l|
p l
}
When run, the output is:
$ ruby /tmp/select_test.rb
[#IO:0x496a8, #IO:0x495d0]
“out(65280): #\n”
[#IO:0x496a8, #IO:0x495d0]
“out(65280): # Internet host table\n”
[#IO:0x496a8, #IO:0x495d0]
“out(65280): #\n”
[#IO:0x496a8, #IO:0x495d0]
“out(65280): 127.0.0.1\tlocalhost \n”
[#IO:0x496a8, #IO:0x495d0]
“out(65280): 172.17.100.124\tblue.mxim.com blue\n”
[#IO:0x496a8, #IO:0x495d0]
“out(65280): \tparis.mxim.com loghost\n”
[#IO:0x496a8, #IO:0x495d0]
“out(65280): 172.17.100.5\tparis.mxim.com loghost\n”
[#IO:0x496a8, #IO:0x495d0]
""
[#IO:0x496a8, #IO:0x495d0]
""
[#IO:0x496a8, #IO:0x495d0]
""
[#IO:0x496a8, #IO:0x495d0]
… repeat forever …
This does not seem right. First, there is never any data on the error
object, so why is select saying there is? Second once the end of the
file is reached, why is select continuing to claim both descriptors
have data? I’m sure I’m doing something wrong…
Eventually I’d like the “run_command” method to detect that
the external program has exited and check the return code (via $?),
raising an exception if neccessary. That way I can process output one
line at a time, but still check return codes from the external program.
Any insights, suggestions, or help will be greatly appreciated.
Thanks,
Jeff.
···
–
Jeff Putsch Email: putsch@mxim.com
Maxim Integrated Products Office: (503)547-2037
High Frequency CAD Engineering