Here's one I wrote probably needs revisited

(defn doCmd
        "do any command"
        ([& params]
                (let [cmd (new java.util.ArrayList)]
                        (doseq atom params
                                (let [#^String prms (. atom split " ")]
                                        (doseq p prms
                                                (. cmd add p))))
                        (let [proc (new java.lang.ProcessBuilder cmd)
                                        isr (new java.io.InputStreamReader (.. 
proc start
getInputStream))
                                        sb (new StringBuilder)]
                                        (with-open br (new 
java.io.BufferedReader isr)
                                                (loop [c (. br (read))]
                                                  (if (neg? c)
                                                         (str sb)
                                                         (do
                                                                (. sb (append 
(char c)))
                                                                (recur (. br 
(read)))))))))))


On Aug 25, 8:38 am, "Michael Reid" <[EMAIL PROTECTED]> wrote:
> Hi Parth,
>
> On 8/25/08, Parth Malwankar <[EMAIL PROTECTED]> wrote:
>
>
>
> >  I want to run a shell command through Clojure
> >  so I tried the following which doesn't work:
>
> By "doesn't work" do you mean that you don't see any output from the 
> processes?
>
> First thing to understand is that processes created in this manner do
> not get a terminal or console, as documented in the java.lang.Process
> class:
>
>  http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Process.html
>
> Instead, the I/O streams are wrapped w/ Java I/O stream objects. In
> this case of 'vim' this may quite possibly prevent any useful
> interaction with the the process. In the case of 'ls' the key might be
> to simply grab the output stream of the process
> (Process.getOutputStream) and dump the output to System.out or
> wherever else is appropriate for your needs.
>
> Can't test this right now, so this might be way off base.
>
> --
> /mike.
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to