Created
January 6, 2011 15:38
-
-
Save rlm/768026 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import '(java.io File BufferedReader ByteArrayOutputStream InputStreamReader)) | |
(def println-repl (bound-fn* println)) | |
(defn sh-seq | |
"same as sh but returns a lazy seq of the programs stdout, and prints all errors to the repl" | |
[& command+args] | |
(let [process (.exec (Runtime/getRuntime) (apply str (interpose " " command+args)))] | |
(let [reader (clojure.java.io/reader (.getInputStream process) :encoding "UTF-8")] | |
(line-seq reader)))) | |
(defn sh-seq-debug | |
"same as sh-seq but prints all errors to the repl" | |
[& command+args] | |
(let [process (.exec (Runtime/getRuntime) (apply str (interpose " " command+args)))] | |
(let [reader (clojure.java.io/reader (.getInputStream process) :encoding "UTF-8") | |
error-reader (clojure.java.io/reader (.getErrorStream process) :encoding "UTF-8")] | |
(.start (Thread. #(dorun (map println-repl (line-seq error-reader))))) | |
(line-seq reader)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment