Hi Users of Shell-out,

I'd sometimes like to have the exit status from system commands, so I
patched clojure.contrib.shell-out to accept a :verbose option which,
when turned on, returns a map with :exit, :out, & :err (where :exit's
value is the exit code int, & :out & :err name either byte arrays or
strings).

Anyone else have an interest in such a feature? In particular, would
the option be handy for lancet?

The modified sh function is below for reference, but I'll submit an
issue & patch to contrib if invited to.

Thanks,
Perry

(defn sh
  ; doc string elided
  [& args]
  (let [opts (parse-args args)
        proc (.exec (Runtime/getRuntime)
                    (into-array (:cmd opts))
                    (as-env-string (:env opts))
                    (as-file (:dir opts)))
        in-stream (.getInputStream proc)]
    (when (:in opts)
      (with-open [osw (OutputStreamWriter. (.getOutputStream proc))]
        (.write osw (:in opts))))
    (let [stdout (.getInputStream proc)
          stderr (.getErrorStream proc)
          [[out err] combine-fn]
            (if (= (:out opts) :bytes)
              [(for [strm [stdout stderr]]
                (into-array Byte/TYPE (map byte (stream-seq strm))))
               #(into-array Byte/TYPE (concat %1 %2))]
              [(for [strm [stdout stderr]]
                (apply str (map char (stream-seq
                                       (InputStreamReader. strm (:out
opts))))))
                 str])
           exit-code  (.waitFor proc)]
      (if (:verbose opts)
        {:exit exit-code :out out :err err}
        (combine-fn out err)))))

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