diff options
author | Stuart Halloway <stu@thinkrelevance.com> | 2010-07-01 13:26:47 -0400 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2010-07-09 15:02:42 -0400 |
commit | 31b6fb557a3c524c447d312f5c51b6262ffb9b0f (patch) | |
tree | 92e48bb34d623939771d78f223cdcd6a1ec3e464 | |
parent | 7def88afe28221ad78f8d045ddbd87b5230cb03e (diff) |
fixes to #392:
- correct order for branches for in
- :out and :outenc are separate things
- stderr always gets platform encoding
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r-- | src/clj/clojure/java/shell.clj | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/clj/clojure/java/shell.clj b/src/clj/clojure/java/shell.clj index 62cabe16..f20c72e9 100644 --- a/src/clj/clojure/java/shell.clj +++ b/src/clj/clojure/java/shell.clj @@ -69,10 +69,17 @@ collecting its stdout"} (.toByteArray bout))) (defn- stream-to-string - [in enc] - (with-open [bout (StringWriter.)] - (copy in bout :encoding enc) - (.toString bout))) + ([in] (stream-to-string in (.name (Charset/defaultCharset)))) + ([in enc] + (with-open [bout (StringWriter.)] + (copy in bout :encoding enc) + (.toString bout)))) + +(defn- stream-to-enc + [stream enc] + (if (= enc :bytes) + (stream-to-bytes stream) + (stream-to-string stream enc))) (defn sh "Passes the given strings to Runtime.exec() to launch a sub-process. @@ -116,19 +123,17 @@ collecting its stdout"} (if in (future (if (instance? (class (byte-array 0)) in) - (with-open [osw (OutputStreamWriter. (.getOutputStream proc) (:inenc opts))] - (.write osw in)) (with-open [os (.getOutputStream proc)] - (.write os in)))) + (.write os in)) + (with-open [osw (OutputStreamWriter. (.getOutputStream proc) (:inenc opts))] + (.write osw in)))) (.close (.getOutputStream proc))) (with-open [stdout (.getInputStream proc) stderr (.getErrorStream proc)] - (let [[out err] - (if (= (:outenc opts) :bytes) - (pmap #(stream-to-bytes %) [stdout stderr]) - (pmap #(stream-to-string % (:outenc opts)) [stdout stderr])) + (let [out (stream-to-enc stdout (:outenc opts)) + err (stream-to-string stderr) exit-code (.waitFor proc)] - {:exit exit-code :outenc out :err err})))) + {:exit exit-code :out out :err err})))) (comment |