From: ara.t.howard@... Date: 2006-11-17T08:53:04+09:00 Subject: Re: popen, open3 problems On Fri, 17 Nov 2006, Peter Schrammel wrote: > Hi, > > I think this problem is surely solved but hven't found anything on the net: > > I get two programs: > 1. a ruby (master) > 2. a perl (slave) > > I want the master to set commands to the slave and wait for the answer > (repeatedly). So a conversation could look like this: > > m: set_var > m: v=8 > s: set > m: get_var > m: v > s: 8 > ... > > The problem is that ruby refuses to write to stdin of the slave until I > close the pipe. But I want to use the pipe repeatedly. Did I miss > something about IPC? man stdio /buffer > > My curent progs look like this: > > > require 'fcntl' > require 'open3' harp:~ > cat a.rb require 'open3' Open3.popen3 "perl a.pl" do |i,o,e| i.puts 'set_var' i.puts 'v=8' i.flush # <<--- puts o.gets end harp:~ > cat a.pl $| = 1; # <<--- while ($line = ) { chomp($line); if ($line eq "set_var") { &set_var;} elsif ($line eq "quit") { exit 0;} } sub set_var { $var=; chomp($var); print "set.$var\n"; } harp:~ > ruby a.rb set.v=8 -a -- my religion is very simple. my religion is kindness. -- the dalai lama