Kerl, John on Thu, 08 Jan 2004 20:36:21 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

RE: Using fifos for in/output


Can't you use popen() in C?

-----Original Message-----
From: Prof. J. E. Cremona [mailto:John.Cremona@maths.nottingham.ac.uk]
Sent: Thursday, January 08, 2004 7:16 AM
To: pari-dev@list.cr.yp.to
Subject: Using fifos for in/output


[I am sending this to pari-dev, though I do not seem to have received
anything from pari-dev for ages.  So this is partly a test to see if I
still subscribed to that.]

A couple of months ago there were some interesting postings from Bill
and Karim about using a fifo (special unix file) for input.  I am
interested in using a second fifo for output as well, either by
redirecting stout or by using write().

I really want this to work from within a C/C++ program, so that I can
start up a gp process in the background, have my program occasionally
send it input lines via its input fifo and then pick up the (one-line)
output from its output fifo.  This would be more efficient than my
current practice of starting a new "slave" gp for each such
calculation, and getting its output via a temporary (ordinary) file to
which gp directs its output.

As a first test, I tried this but it doesn't work:

1. Create fifos called gpin and gpout.
2. (In window 1) start gp with
   gp -q -f < gpin > gpout 
3. (In window 2) In a separate window do
   tail -f gpout
4. (In window 3) In a 3rd window do
   cat >> gpin

And then I would hope that any gp input lines I type into window 3
will be processed by gp and the output seen in window 2.  This almost
works, except that nothing appears in window 2 until I type \q into
window 3, when I get all the output at once.   Can one force gp to
flush its output buffer?

Similar behaviour if the input is not redirected but instead gp is
started with the line "\r gpin".

Second test:  Same fifos.
In Window 1 I start gp -f -q (no redirections) and "manually" give it
the line \r gpin . 
In Window 2 I again do tail -f gpout
In Window 3 I send to gpin lines of the form write("gpout",123)

-- but nothing appears in Window 2, and as far as I can see gp never
gets the contents of gpin.

Am I trying the impossible,  or would this work if I did it
differently?

John Cremona