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?

Thanks


My curent progs look like this:


require 'fcntl'
require 'open3'

pin, pout, perr = Open3.popen3('perl test.pl')
    pin.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)
    pout.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)
    perr.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)

pin.syswrite "set_var\n"
pin.syswrite "v=8\n"
#pin.close_write   #<----------don't want to do this but have to!
result=pout.readline
puts result
#pin.close
pout.close
perr.close

---------------------------------------------------------------------------
perl slave:

while ($line = <STDIN>) { #first line is the command
chomp($line);		
if ($line eq "set_var") { &set_var;}
elsif ($line eq "quit") { exit 0;}
}

sub set_var {
$var=<STDIN>; #second...lines are the params; get the var
chomp($var);
print "set.";  #return a confirmation
}