This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-04
Channels
- # announcements (3)
- # aws (13)
- # babashka (10)
- # beginners (30)
- # biff (1)
- # calva (59)
- # chlorine-clover (11)
- # cider (3)
- # circleci (2)
- # clojars (22)
- # clojure (21)
- # clojure-europe (2)
- # clojurescript (10)
- # core-typed (2)
- # fulcro (8)
- # girouette (12)
- # graphql (1)
- # helix (6)
- # inf-clojure (4)
- # joyride (6)
- # leiningen (7)
- # off-topic (3)
- # pathom (44)
- # polylith (13)
- # shadow-cljs (44)
- # tools-deps (1)
I want to run a subprocess, and handle stdout and stderr differently. I came up with:
(defn run-handling-lines
"Runs the command, passing each stdout/stderr line to the relevant handler.
Returns the process exit code."
[command handle-stdout handle-stderr]
(let [proc (p/process command {:shutdown p/destroy-tree})
reader->channel (fn [r]
(let [c (chan)]
(start-thread #(binding [*in* r]
(loop [line (read-line)]
(when (not (nil? line))
(>!! c line)
(recur (read-line))))
(>!! c :exit)))
c))]
(with-open [reader-stdout (io/reader (:out proc))
reader-stderr (io/reader (:err proc))]
(let [stdout-chan (reader->channel reader-stdout)
stderr-chan (reader->channel reader-stderr)]
(loop []
(let [[line c] (alts!! [stdout-chan stderr-chan])
handler (condp = c
stdout-chan handle-stdout
stderr-chan handle-stderr)]
(when (not= line :exit)
(spy line)
(handler line)
(recur))))))
(:exit @proc)))
But it feels really complicated for what it does, am I missing on some obvious clj or bb mechanism?I think that's a reasonable approach. Usually I write a loop
and a future which reads from those streams with read-line
Thanks @U04V15CAJ, I'll look into futures.
Perhaps a naive question, but say I want to manage my static blog with netlify, using babashka. How does that work? Do I setup a script that downloads babashka from somewhere? Run the script locally and commit the results directly to git, letting Netlify just publish a pre-built site?
Maybe @U8WFYMFRU can say something about this, I haven't got much netlify experience
Hey there was experimenting with this. Currently I experimented with using node babashka to implement a few tasks to build static files then can publish them to netlify. You could also have netlify build on git push or use an action
Same could be done with babashka. I chose nbb since there is a huge library of modern frontend tools to leverage in static site building.