Lisp HUG Maillist Archive

sys:open-pipe, closing one way of :io

Hello all, Im trying to use Argonne's otter via sys:open-pipe. I'm 
working under LWL4.4 right now, but will also be getting to the Mac
side of things too. I've got otter on my default path, 
so something like

 
> (let ((p (sys:open-pipe "otter" :direction :output)))
       (loop for line in '("set(binary_res)."
                          "formula_list(usable)."
                          "all x (Man(x) -> Mortal(x))."
                          "Man(socrates)."
                          "end_of_list."
                          "formula_list(sos)."
                          "-Mortal(socrates)."
                          "end_of_list.") do
            (write-string line p))
     (finish-output p)
     (close p))

will cause otter to output all the correct output to the xterm from which
I started lispworks. If I use "otter > temp.otter.out" rather than "otter",
I get the correct results in the temp file. 

The problem is, rather than reading from file, I'd prefer to just read
from a pipe. So I specify :direction :io. In that case, however, I can't
just (close p), because I do need to read from p (to get the output). 
Otter doesn't seem to start doing anything until its input is closed.
(normally I invoke it as "otter < input.in"). Is there a way to close just
my output (otter's input) side of the system::pty-stream that is
returned by sys:open-pipe ?


=====================
Joshua Taylor
tayloj@rpi.edu


Re: sys:open-pipe, closing one way of :io

On Feb 9, 2005, at 10:24 AM, Joshua Taylor wrote:

> Otter doesn't seem to start doing anything until its input is closed.
> (normally I invoke it as "otter < input.in"). Is there a way to close 
> just
> my output (otter's input) side of the system::pty-stream that is
> returned by sys:open-pipe ?


Have you tried to call FORCE-OUTPUT or FINISH-OUTPUT to flush your 
output stream?

John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL


Re: sys:open-pipe, closing one way of :io

Yes indeed, I have. I was hoping that as Ctrl-D works on a console, that
sending the char #\eot and finish/force-output would get it to realize that 
input was done. Alas though, I only get an error about an invalid input 
char. If I were working with normal unix pipes (int array[2]), I'd just close 
that end when I was done. I don't really see a way to do that in this
situation.


On Wed, 9 Feb 2005 11:03:38 -0500, John DeSoi <desoi@pgedit.com> wrote:
> 
> On Feb 9, 2005, at 10:24 AM, Joshua Taylor wrote:
> 
> > Otter doesn't seem to start doing anything until its input is closed.
> > (normally I invoke it as "otter < input.in"). Is there a way to close
> > just
> > my output (otter's input) side of the system::pty-stream that is
> > returned by sys:open-pipe ?
> 
> Have you tried to call FORCE-OUTPUT or FINISH-OUTPUT to flush your
> output stream?
> 
> John DeSoi, Ph.D.
> http://pgedit.com/
> Power Tools for PostgreSQL
> 
> 


-- 
=====================
Joshua Taylor
tayloj@rpi.edu


Re: sys:open-pipe, closing one way of :io

On Wed, 9 Feb 2005 10:24:06 -0500, Joshua Taylor <joshuaaaron@gmail.com> wrote:

> Hello all, Im trying to use Argonne's otter via sys:open-pipe. I'm
> working under LWL4.4 right now, but will also be getting to the Mac
> side of things too. I've got otter on my default path, so something
> like
>
>  
>> (let ((p (sys:open-pipe "otter" :direction :output)))
>        (loop for line in '("set(binary_res)."
>                           "formula_list(usable)."
>                           "all x (Man(x) -> Mortal(x))."
>                           "Man(socrates)."
>                           "end_of_list."
>                           "formula_list(sos)."
>                           "-Mortal(socrates)."
>                           "end_of_list.") do
>             (write-string line p))
>      (finish-output p)
>      (close p))
>
> will cause otter to output all the correct output to the xterm from
> which I started lispworks. If I use "otter > temp.otter.out" rather
> than "otter", I get the correct results in the temp file.
>
> The problem is, rather than reading from file, I'd prefer to just
> read from a pipe. So I specify :direction :io. In that case,
> however, I can't just (close p), because I do need to read from p
> (to get the output).  Otter doesn't seem to start doing anything
> until its input is closed.  (normally I invoke it as "otter <
> input.in"). Is there a way to close just my output (otter's input)
> side of the system::pty-stream that is returned by sys:open-pipe ?

I had a similar problem when porting ASDF-INSTALL to LW and came up
with a kludge like this:

  (sys:open-pipe (format nil "echo '~A' | otter"
                             otter-commands)
                 ...

Does that help in your case?  Maybe with "echo -e" instead of "echo"
if needed?

If it works it's still a kludge, though.  I'd be very happy if
OPEN-PIPE offered the option to get separate streams as in CMUCL,
SBCL, or AllegroCL.

Cheers,
Edi.


Re: sys:open-pipe, closing one way of :io

It is a little kludgey, but it does work without the need for
temporary files. I think
that unless someone shows me a way to close the components of the pipe
individually, This will be the method I use.


On Wed, 09 Feb 2005 17:37:20 +0100, Edi Weitz <edi@agharta.de> wrote:
> On Wed, 9 Feb 2005 10:24:06 -0500, Joshua Taylor <joshuaaaron@gmail.com> wrote:
> 
> > Hello all, Im trying to use Argonne's otter via sys:open-pipe. I'm
> > working under LWL4.4 right now, but will also be getting to the Mac
> > side of things too. I've got otter on my default path, so something
> > like
> >
> >
> >> (let ((p (sys:open-pipe "otter" :direction :output)))
> >        (loop for line in '("set(binary_res)."
> >                           "formula_list(usable)."
> >                           "all x (Man(x) -> Mortal(x))."
> >                           "Man(socrates)."
> >                           "end_of_list."
> >                           "formula_list(sos)."
> >                           "-Mortal(socrates)."
> >                           "end_of_list.") do
> >             (write-string line p))
> >      (finish-output p)
> >      (close p))
> >
> > will cause otter to output all the correct output to the xterm from
> > which I started lispworks. If I use "otter > temp.otter.out" rather
> > than "otter", I get the correct results in the temp file.
> >
> > The problem is, rather than reading from file, I'd prefer to just
> > read from a pipe. So I specify :direction :io. In that case,
> > however, I can't just (close p), because I do need to read from p
> > (to get the output).  Otter doesn't seem to start doing anything
> > until its input is closed.  (normally I invoke it as "otter <
> > input.in"). Is there a way to close just my output (otter's input)
> > side of the system::pty-stream that is returned by sys:open-pipe ?
> 
> I had a similar problem when porting ASDF-INSTALL to LW and came up
> with a kludge like this:
> 
>   (sys:open-pipe (format nil "echo '~A' | otter"
>                              otter-commands)
>                  ...
> 
> Does that help in your case?  Maybe with "echo -e" instead of "echo"
> if needed?
> 
> If it works it's still a kludge, though.  I'd be very happy if
> OPEN-PIPE offered the option to get separate streams as in CMUCL,
> SBCL, or AllegroCL.
> 
> Cheers,
> Edi.
> 
> 


-- 
=====================
Joshua Taylor
tayloj@rpi.edu


Updated at: 2020-12-10 08:53 UTC