guile-user
[Top][All Lists]
Advanced

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

Re: Using open-input-output-pipe


From: Chris Vine
Subject: Re: Using open-input-output-pipe
Date: Mon, 22 Jan 2018 11:00:35 +0000

> On 01/21/2018 12:31 PM, Edwin Watkeys wrote:
> 
> > Hi all,
> >
> > I'm trying to write a procedure that processes some input through a
> > unix utility. Open-input-output-pipe returns a bidirectional pipe
> > that I can both read and write to. However, there is no way that I
> > can figure out to tell the external process that input is complete,
> > as there is no way to determine the output port of the rw-port and
> > therefore no way to close it. Closing an rw-port closes both the
> > read and write ports.
> >
> > Open-input-output-port therefore seems useful for line-based
> > external processes but not for ones that function on the entirety
> > of user input e.g. wc and sort.
> >
> > Is my analysis of the situation roughly accurate?
> >
> > Regards,
> > Edwin

If you want fine-grained control, you might want to look at some of the
procedures in guile-lib's (os process) module, and in particular the
'run-with-pipe' procedure, or using its 'run-concurrently+' procedure
with guile's 'pipe' (the parent can block on its read pipe once it has
completed writing to the child until the child process closes the other
end of the pipe upon finishing, causing the parent to get an eof-object
provided it has itself previously closed the write end of its read
pipe).

Otherwise if you want to stick to guile proper, you may have to do it by
hand.  As 'pipe' gives you an input and output port for each pipe which
can be independently closed, you could use two of these with the
'dup2', 'fork' and 'execl' procedures.  It's tedious though.

Chris



reply via email to

[Prev in Thread] Current Thread [Next in Thread]