Fork me on GitHub
#babashka
<
2019-12-16
>
borkdude22:12:56

$ cat /tmp/pb.clj
#!/usr/bin/env bb

(require '[ :as io])

(defn grep [input pattern]
  (let [proc (-> (ProcessBuilder. ["grep" pattern])
                 (.start))
        proc-input (.getOutputStream proc)
        proc-output (.getInputStream proc)]
    (with-open [w (io/writer proc-input)]
      (binding [*out* w]
        (print input)
        (flush)))
    (.waitFor proc)
    (print (slurp proc-output))
    (flush)))

(grep "hello\nbye\n" "bye")

$ bb /tmp/pb.clj
bye
(`processbuilder` branch)