From: jimka
Subject: how to concatenate two streams
Date: 
Message-ID: <0f902908-a707-44e2-84da-bc1770ab2d86@z27g2000prd.googlegroups.com>
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

From: Pascal J. Bourguignon
Subject: Re: how to concatenate two streams
Date: 
Message-ID: <7cd4e7ign5.fsf@pbourguignon.anevia.com>
jimka <·····@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__
From: jimka
Subject: Re: how to concatenate two streams
Date: 
Message-ID: <0dbc0e2c-1684-4a4e-af25-1fd1be2aca37@z28g2000prd.googlegroups.com>
>
> > 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 ?
From: Thomas A. Russ
Subject: Re: how to concatenate two streams
Date: 
Message-ID: <ymiocxrqkvb.fsf@blackcat.isi.edu>
jimka <·····@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
From: D Herring
Subject: Re: how to concatenate two streams
Date: 
Message-ID: <4980b00f$0$3339$6e1ede2f@read.cnntp.org>
jimka wrote:
>>> 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 ?

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))
From: Pascal J. Bourguignon
Subject: Re: how to concatenate two streams
Date: 
Message-ID: <87pri71ao6.fsf@galatea.local>
jimka <·····@rdrop.com> writes:

>>
>> > 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 ?

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__