diff --git a/src/babashka/process.cljc b/src/babashka/process.cljc index 5b555cd..4070db9 100644 --- a/src/babashka/process.cljc +++ b/src/babashka/process.cljc @@ -592,3 +592,8 @@ (tokenize cmd)) cmd (into cmd args)] (check (process prev cmd (merge default-shell-opts opts))))) + +(defn alive? + "Returns `true` if the process is still running and false otherwise." + [p] + (.isAlive ^java.lang.Process (:proc p))) diff --git a/test/babashka/process_test.cljc b/test/babashka/process_test.cljc index 1225f15..39d8201 100644 --- a/test/babashka/process_test.cljc +++ b/test/babashka/process_test.cljc @@ -285,6 +285,13 @@ (jdk9+) +(deftest alive-lives + (let [{:keys [in] :as res} (process '[cat])] + (is (true? (p/alive? res))) + (.close in) + @res + (is (false? (p/alive? res))))) + ;;;; Windows tests ;;;; Run with clojure -M:test -i windows