From: Jeff Putsch Date: 2002-08-22T04:18:53+09:00 Subject: Re: select on solaris On Thu, Aug 22, 2002 at 03:53:51AM +0900, Jeff Putsch wrote: > 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 > } Sorry, I botched the simple program. Here are two simple examples illustrating my confusion: #!/usr/sepp/bin/ruby def run_command f = IO.popen("cat /etc/hosts") while not (r=select([f])).nil? p r p r[0][0].gets.to_s end end run_command and #!/usr/sepp/bin/ruby require 'open3' def run_command (stdin, out, err) = Open3.popen3("cat /etc/hosts") while not (r=select([out,err])).nil? p r p "out: "+r[0][0].gets.to_s p "err: "+r[0][1].gets.to_s end end run_command In both cases select returns that data is ALWAYS ready. The first example gives this output: [[#], [], []] "#\n" [[#], [], []] "# Internet host table\n" [[#], [], []] "#\n" [[#], [], []] "127.0.0.1\tlocalhost \n" [[#], [], []] "172.17.100.124\tblue.mxim.com blue\n" [[#], [], []] "\tparis.mxim.com loghost\n" [[#], [], []] "172.17.100.5\tparis.mxim.com loghost\n" [[#], [], []] "" [[#], [], []] "" [[#], [], []] "" The second is similar, but shows the "err" never has any data. So why is select doing this? What am I doing wrong? Once I get select working, I'd like to be using the Open3.popen3() version and detecting when the input data is done (a time out may not work), then check the return code of the program called by Open3.popen3(). Any advice and/or pointers will be greatly appreciated. Thanks, Jeff. -- Jeff Putsch Email: putsch@mxim.com Maxim Integrated Products Office: (503)547-2037 High Frequency CAD Engineering