On Thursday 18 December 2008 13:33, Stephan Mühlstrasser wrote:
> On Dec 18, 10:01 pm, Randall R Schulz <rsch...@sonic.net> wrote:
> > > My question was not precise enough. I meant why can the parent
> > > process - the Clojure program - terminate before all all the
> > > output has been passed through.
> >
> > Because it can terminate whenever it wants to. Child processes do
> > not place any constraints upon their parents, at least not on Unix
> > systems.
>
> I understand that the parent process can terminate whenever it wants.
> But in my program the "copy" function recurs over readLine until it
> returns null/nil, so it should read until the end of the output from
> the child process. And the calling thread waits for the completion of
> the agent functions with (await ...). The main thread should not come
> out of the (await ...) until both agent functions have copied their
> whole stream... But somehow the "copy" function is interrupted when
> the child process terminates.
>
> Maybe the missing piece is how your (cat-stream ...) function works,
> which is not included in your listing. How does it copy the data?

Nothing fancy:

(defn cat-stream
 "Copy bytes from an InputStream to *out*"
 [stream]
 (let [reader (new BufferedReader (new InputStreamReader stream))
       buffer (make-array Character/TYPE 1024)]
  (loop [n-read (.read reader buffer)]
   (when (> n-read 0)
    (.write *out* buffer 0 n-read)
    (recur (.read reader buffer))))
  (.flush *out*)))


> Regards
> Stephan


Randall Schulz

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to