Skip to content

Instantly share code, notes, and snippets.

@SevereOverfl0w
Created March 13, 2019 19:07
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 SevereOverfl0w/c4c8876f20d6ce1772a77e2cc216d814 to your computer and use it in GitHub Desktop.
Save SevereOverfl0w/c4c8876f20d6ce1772a77e2cc216d814 to your computer and use it in GitHub Desktop.
(ns user
(:import [org.cactoos.io InputOf TeeInput]
[org.buildobjects.process ProcBuilder]
[org.zeroturnaround.exec ProcessExecutor]
[org.apache.commons.io.input ReaderInputStream]
[org.apache.commons.io.output WriterOutputStream]))
(defn reload
[]
(require 'user :reload))
(defn *in*-stream
[]
(new org.cactoos.io.InputStreamOf *in*))
(defn *out*-stream
[]
(new org.cactoos.io.OutputStreamTo *out*))
(defn *in*-stream-alt
[]
(new ReaderInputStream *in* "UTF-8"))
(defn *out*-stream-alt
[]
(new WriterOutputStream *out* "UTF-8"))
(defn vim
[]
(-> (new ProcessExecutor)
(.command (into-array String ["nvim"]))
(.redirectOutput (*out*-stream-alt))
(.redirectInput (*in*-stream-alt))
(.execute)))
(defn foo
[]
(with-open [out (*out*-stream-alt)
in (*in*-stream-alt)]
(-> (new ProcBuilder "/bin/sh" (into-array String ["-c" "sleep 1 && echo 'HI' && read FOO"]))
(.withOutputStream out)
(.withInputStream in)
(.run))))
(defn foo2
[]
(let [in (*in*-stream-alt)]
(-> (new ProcessExecutor)
(.command (into-array String ["/bin/sh" "-c" "sleep 1 && echo 'HI'"]))
(.redirectOutput (*out*-stream-alt))
(.redirectInput in)
(.execute))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment