Ara.T.Howard wrote:
> 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
The wrapper didn't work, but I found a solution
I just send an extra empty command after each command.

-- 
Roeland