From: "Ara.T.Howard" Date: 2004-05-15T03:53:53+09:00 Subject: Re: getc windows != linux On Fri, 14 May 2004, Roeland Moors wrote: > I'm trying to communicate with a program (gnucap) using ruby. > > The versions of ruby (1.8.1) and gnucap (0.34) are the same on windows > and linux. > > When I start gnucap, this is the output: > > Gnucap 0.34 > The Gnu Circuit Analysis Package > Never trust any version less than 1.0 > Copyright 1982-2002, Albert Davis > Gnucap comes with ABSOLUTELY NO WARRANTY > This is free software, and you are welcome > to redistribute it under certain conditions > according to the GNU General Public License. > See the file "COPYING" for details. > gnucap> _ > > > > Here is a simple ruby test program: > > <-- CODE --> > #!/usr/bin/env ruby -w > > gnucap = IO.popen("gnucap", "w+") > output = "" > while output !~ /.*#{"gnucap>"}$/ > char = gnucap.getc.chr > output += char > end > puts "ok" > <-- CODE --> > > In Linux this program works and shows me "ok". But on windows the > program stops reading after the last newline: "...details." > This means the program never reach ok. > It keeps waiting for input. > > Any ideas or suggestions? > > Thanks the output from gnucap on window must be line buffered - because it hasn't sent a newline the last line with 'gnucap> ' on it has not been flushed and is not available for reading. i bet that, if you ran a few hundred times, you'd see this behaviour with linux too. i dont know if gnucap.sync = true will work if not perhaps you could write alittle wrapper like this file: wgnucap.rb ============== #!/usr/bin/env ruby STDOUT.sync = true STDERR.sync = true cmd = 'gnucap ' + ARGV.join(' ') exec cmd though i don't really know about windows... -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | URL :: http://www.ngdc.noaa.gov/stp/ | TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done ===============================================================================