A Clojure core.async wrapper around the excellent NuProcess library by Brett Wooldridge for efficiently interacting with a potentially large number of subprocesses concurrently.
Add the following dependency to your project.clj
file:
The following is a roughly complete demonstration of features and usage:
(require '[asynp.core :refer [run-process wait-for-process shutdown-process
close-stdin-for-process write-str-to-process
log-strings decode-chars]])
(let [process-dict (run-process ["/bin/cat"])]
;; set up readers for stderr and stdout
(log-strings (decode-chars (:out process-dict)) \u0000)
(log-strings (decode-chars (:err process-dict)) \newline)
;; write content
(write-str-to-process process-dict "Hello world\u0000Partial write")
(Thread/sleep 1000)
(write-str-to-process process-dict "...completed\u0000")
;; close stdin
(close-stdin-for-process process-dict)
;; wait for 5 seconds for the process to exit, then force a shutdown
(println (str "Exit status: " (wait-for-process process-dict 5000)))
(shutdown-process process-dict))
Copyright © 2014 ThreatGRID, Inc.
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.