Skip to content

Instantly share code, notes, and snippets.

@fsvehla
Created May 4, 2012 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fsvehla/2595281 to your computer and use it in GitHub Desktop.
Save fsvehla/2595281 to your computer and use it in GitHub Desktop.
(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