Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to concatenate two streams

9 views
Skip to first unread message

jimka

unread,
Jan 28, 2009, 10:18:42 AM1/28/09
to
does anyone know how to concatenate two streams in common lisp?

I.e., i have an input stream which i'd like to pass to the sb-ext:run-
program function, however, i'd like to
prepend several lines of input so that sb-ext:run-program will firsts
read the prespended stings
then read the rest of the stream.

i've thought of someone reading the first into a string, then
concatenating the strings,
then making a new stream which reads from the string. maybe there is
an easier way???

-jim

Pascal J. Bourguignon

unread,
Jan 28, 2009, 10:39:42 AM1/28/09
to
jimka <ji...@rdrop.com> writes:

> does anyone know how to concatenate two streams in common lisp?

MAKE-CONCATENATED-STREAM


> I.e., i have an input stream which i'd like to pass to the sb-ext:run-
> program function, however, i'd like to
> prepend several lines of input so that sb-ext:run-program will firsts
> read the prespended stings
> then read the rest of the stream.

Here you have a different problem. Lisp streams are not unix pipes.
You would have to read in lisp from your concatenate stream and
forward the data to your inferior process thru the unix pipe (ie. the
:input stream argument to run-program).


> i've thought of someone reading the first into a string, then
> concatenating the strings,
> then making a new stream which reads from the string. maybe there is
> an easier way???

Yes, just concatenate the streams with the above mentionned function,
and copy that stream to the input of the inferior program.

--
__Pascal Bourguignon__

jimka

unread,
Jan 28, 2009, 10:53:10 AM1/28/09
to

>
> > i've thought of someone reading the first into a string, then
> > concatenating the strings,
> > then making a new stream which reads from the string. maybe there is
> > an easier way???
>
> Yes, just concatenate the streams with the above mentionned function,
> and copy that stream to the input of the inferior program.
>
> --
> __Pascal Bourguignon__


but the function i'm calling expects a stream. what stream should i
give it?
you are saying that i cannot pass the concatenated stream to
the :input key
of sb-ext:run-program ?

D Herring

unread,
Jan 28, 2009, 2:20:48 PM1/28/09
to

try something like
(sb-ext:run-program prog args :input (make-concatenated-stream s0 s1))

or
(let ((s (make-concatenated-stream s0 s1)))
(sb-ext:run-program prog args :input s))

Pascal J. Bourguignon

unread,
Jan 28, 2009, 2:40:41 PM1/28/09
to
jimka <ji...@rdrop.com> writes:

That's what I said, yes, but I didn't read the manual.

It seems to say that you can:
http://sbcl.sourceforge.net/manual/Running-external-programs.html#Running-external-programs

* (with-output-to-string (output)
(with-input-from-string (s1 "Hello
")
(with-input-from-string (s2 "world
")
(let ((input (make-concatenated-stream s1 s2)))
(sb-ext:run-program "/usr/bin/tr" '("a-z" "A-Z") :input input :output output :wait t)))))

"HELLO
WORLD
"

--
__Pascal Bourguignon__

Thomas A. Russ

unread,
Jan 28, 2009, 2:41:12 PM1/28/09
to
jimka <ji...@rdrop.com> writes:

> but the function i'm calling expects a stream. what stream should i
> give it?
> you are saying that i cannot pass the concatenated stream to
> the :input key
> of sb-ext:run-program ?

I would expect that you could just use the concatenated stream.
See below:

(sb-ext:run-program "/bin/cat" nil
:input (make-concatenated-stream
(make-string-input-stream "foo bar")
(make-string-input-stream "baz bump"))
:output *standard-output*)
foo barbaz bump

--
Thomas A. Russ, USC/Information Sciences Institute

0 new messages