Re: making pipes

Jan Wielemaker <[email protected]> Mon, 14 Apr 2014 10:18:49 +0200
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 04/14/2014 08:54 AM, Ross Boylan wrote:
> How can I get the output of one process to be the input of another?
>
> The process library says that the options pipes are pipe(-Stream),
> which seems to mean I can not hand an already bound stream to
> process_create.

process_create/3 creates a process and optionally returns streams
that are bound the the I/O of the process.  Next, you read and write
these streams.  So, you can start dot, send the dot data to the program
by writing it to the process input stream (which is an output stream at
Prolog's side) and read the result from the process output stream.

Sometimes you can simply write all data, close the process' input stream
(out output stream) and read the result from the other stream.  Be 
careful though: processes that handle their data in streaming mode will
block if their output is not handled.  This is typically resolved by
starting a separate Prolog thread for either the input or the output.

That is what happens in ClioPatria: it starts dot, the main HTTP handler
copies the output of dot to the HTTP output.  Before doing that, it
starts a thread that generates the graph and writes it to the dot process.

> Is stream_pair/3 relevant?

Not really.  Classical Prolog streams either handle an input or an
output stream.  stream_pair/3 was introduced for compatibility with
SICStus.  It allows for combining an input and and output stream into
a single data structure that is handled by both read and write.

>
> Background: The goal is run dot and then use okular or display to
> open the graph up so I can see it.  I've been looking at
> http://cliopatria.swi-prolog.org/help/source/doc/home/vnc/prolog/src/ClioPatria/components/graphviz.pl?show=src
> for ideas, but it aims to embed in a web page and I'm having some
> difficulty following the full processing path.
>
> I assume I will need to set the relevant pipes to binary mode.

That depends what the application expects.  The default is to use
text stream.  You can use set_stream/2 to change that.

	Cheers --- Jan


>
> Ross Boylan
>
> _______________________________________________ SWI-Prolog mailing
> list [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>