From B.Rowlingson at lancaster.ac.uk  Wed Nov 16 16:58:26 2005
From: B.Rowlingson at lancaster.ac.uk (Barry Rowlingson)
Date: Wed, 16 Nov 2005 15:58:26 +0000
Subject: [Rd] two-way communication using Unix pipes
In-Reply-To: <f68da330511160715m6ad1ab40s6744c67aed1998ff@mail.gmail.com>
References: <f68da330511160715m6ad1ab40s6744c67aed1998ff@mail.gmail.com>
Message-ID: <437B5722.9050302@lancaster.ac.uk>

Jonathan Callahan wrote:

> Can someone please explain to me exactly what R is doing with the the
> standard IO handles and whether or not there is any simple way to convince
> it to behave as if it were talking to a user at the other end of a keyboard
> and terminal? I've already tried '--no-readline' but that doesn't solve my
> problem.
> 

This little noddy example works for me:

#!/usr/bin/perl

use FileHandle;
use IPC::Open2;

$pid=open2(*Reader, *Writer, "R --no-save");
print Writer "x=runif(10);print(mean(x))\n";
while($got=<Reader>){
     print "Got ".$got;
}

Of course, without the \n in the command string it doesnt work at all, 
but I dont see any problems with R reading from stdin and writing to 
stdout....

This is on a Linux box, I dont think you mentioned an OS or platform...

Baz



[Rd] two-way communication using Unix pipes
Barry Rowlingson