The use case for tee is to redirect output to stdout but also to capture it in a file. We could make a built-in construct for this so you can use it to print to stdout but also capture the out stream.
(require '[babashka.process :refer [pipeline pb]]
'[clojure.java.io :as io])
(let [[catp teep] (pipeline (pb ["cat"]) (pb ["tee" "log.txt"] {:out :inherit}))]
;; write to cat every 100 milliseconds 10 times
(future
(with-open [writer (io/writer (:in catp))]
(loop [i 0]
(when (< i 10)
(binding [*out* writer]
(println i)
(flush))
(Thread/sleep 100)
(recur (inc i))))))
@teep ;; wait for the tee process to finish
;; finally we print the file's content
(println (slurp "log.txt")))
(shutdown-agents)
This would be quite useful - i.e. in CI where you might have long running commands you want to interrupt instead of waiting for them to time out or error out
The use case for tee is to redirect output to stdout but also to capture it in a file. We could make a built-in construct for this so you can use it to print to stdout but also capture the out stream.
Also see https://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/output/TeeOutputStream.html
This code is close but doesn't work yet: