Re: How to send EOF to SYS:OPEN-PIPE?
On Tue, 28 Oct 2003 11:08:40 -0500, tarvydas <tarvydas@allstream.net> wrote:
> You either need to open two separate streams - one output, one input
> - and close the output pipe before reading from the input, or, you
> need to rewrite the perl scriptlet so that it runs a simple protocol
> and "knows" when to quit (e.g. it quits when lisp sends it some
> specific character).
>
> p.s. After a quick glance at the manuals, I don't see how to open
> two streams on one shell command, so I would suggest altering the
> perl.
Altering the program is not an option, unfortunately. (It's a C
program and I don't have the source. I used the Perl snippet for
illustration purposes only.)
I had hopes that LW would allow for separate streams like CMUCL or
AllegroCL but it looks like this isn't possible. In CMUCL you can, for
example, do it like this:
(let (prog)
(unwind-protect
(progn
(setq prog
(ext:run-program "/tmp/foo.pl" nil
:output :stream
:input :stream
:wait nil))
(with-open-stream (in (ext:process-input prog))
(write-line "foo" in)
(write-line "bar" in)
(write-line "baz" in))
(with-open-stream (out (ext:process-output prog))
(with-output-to-string (s)
(loop for line = (read-line out nil nil)
while line
do (write-string line s)))))
(ext:process-close prog)))
("foo.pl" is a small Perl script which counts the lines coming from
stdin. This form will actually return the string "3".)
This doesn't work in CMUCL, BTW, if I replace "foo.pl" with the Perl
one-liner from my previous post but this doesn't bother me. I guess
you have to use the :PTY variant of RUN-PROGRAM in this case.
Thanks,
Edi.