On Dec 18, 9:24 pm, Randall R Schulz <rsch...@sonic.net> wrote:
> On Thursday 18 December 2008 12:07, Stephan Mühlstrasser wrote:
>
> > (let [pb (new ProcessBuilder ["sh" "-c" "yes hello | head -1000; echo
> > command finished"])
> > proc (.start pb)
> > stdout (reader (.getInputStream proc))
> > stderr (reader (.getErrorStream proc))
> > stdout-agent (agent stdout)
> > stderr-agent (agent stderr)]
> > (send stdout-agent copy (writer *out*))
> > (send stderr-agent copy (writer *err*))
> > (await stdout-agent stderr-agent)
> > (.waitFor proc)
> > (shutdown-agents)
> > (println "done"))
>
> > Is this use of agents incorrect?
>
> I would say it's an appropriate use, but you need to do it a little
> differently: First of all, use (send-off ...) or you'll have to wait for
> the agent to complete. Then use (await ...) on the agents.
I do use (await ...) on the agents. And I have also tried (send-
off ...), but it didn't make a difference.
> > Why can the program terminate before all the output from the sub-
> > process has been passed through?
>
> As long as the sub-process produces no more output than the operating
> system's pipe buffering limit, it can complete without blocking.
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.
> > Is there a better way to synchronize with sub-processes in Clojure,
> > or is it necessary to synchronize completely at the Java level?
>
> I don't understand this question.
As my approach (implement the synchronization at the Clojure level)
doesn't work obviously, I wondered whether it must be done all at the
Java level, e.g. don't use Clojure agents, but create Java threads
explicitly, start them, and wait for completion by using Java
functions.
> Here's what my implementation looks like. It does not stand alone as
> shown, but you can probably figure out what the missing pieces do:
>
Thanks for sharing this. At first look it looks similar to my
approach, but there must be a certain important detail that is
different.
> Randall Schulz
Regards
Stephan
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---