Created
May 4, 2012 14:54
-
-
Save fsvehla/2595281 to your computer and use it in GitHub Desktop.
This file contains 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
(defn run-process | |
"Runs the process" | |
[args] | |
(->> | |
(new ProcessBuilder args) | |
(.start) | |
)) | |
(defn exec | |
"Returns the ouput of the command, which is assumed to smallish and non-binary." | |
[command & args] | |
(let [process (run-process (into [command] args)) | |
stdout-stream (.. process getInputStream) ] | |
(apply str | |
(map char | |
(take-while | |
(fn [_] | |
; this is expected to have no side-effects. Oops? | |
(> (.available stdout-stream) 0)) | |
(repeatedly #(.read stdout-stream))))))) | |
(exec "ls" "-halps") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment