This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-07
Channels
- # announcements (10)
- # babashka (39)
- # beginners (230)
- # calva (16)
- # cider (20)
- # clara (4)
- # cljs-dev (16)
- # clojure (35)
- # clojure-europe (8)
- # clojure-filipino (5)
- # clojure-france (1)
- # clojure-nl (6)
- # clojure-uk (9)
- # clojuredesign-podcast (1)
- # clojurescript (55)
- # clojurewerkz (1)
- # core-async (13)
- # cursive (1)
- # data-science (1)
- # datomic (4)
- # events (1)
- # fulcro (26)
- # jobs-discuss (1)
- # kaocha (3)
- # malli (53)
- # observability (9)
- # off-topic (1)
- # project-updates (1)
- # re-frame (15)
- # reagent (1)
- # reitit (11)
- # rum (8)
- # sci (29)
- # shadow-cljs (7)
- # vim (12)
- # xtdb (13)
babashka.process, a small wrapper around java.lang.Process. WIP. Feedback welcome: https://github.com/babashka/babashka.process
Cool! I like your design for stdout handling: {:out :inherit}
vs {:out :string}
. In my usages of ProcessBuilder, I have found that I sometimes need to capture stderr to a string. Your process
kind of implies it can do that, but I don’t think that it is implemented yet.
That's really cool - I have a bunch of hairy ECS deployment scripts and moving to bb will simplify a lot of stuff
Rewrite-cljc scripts have an internal shell/command
based on one of your examples I think. Here’s the https://github.com/lread/rewrite-cljc-playground/blob/3aa4741a773ccd329c350208c50a83b1e8ce9671/script/helper/shell.clj#L60.
I also like your naming: process
is more apt that something like shell
or shell-command
.
clojure.java.shell has some stuff around this: https://github.com/clojure/clojure/blob/fe0cfc71e6ec7b546066188c555b01dae0e368e8/src/clj/clojure/java/shell.clj#L93
Oh just re-reading my version, and I did a little https://github.com/lread/rewrite-cljc-playground/blob/3aa4741a773ccd329c350208c50a83b1e8ce9671/script/helper/shell.clj#L21.
I think this will make a very handy addition to babashka! I remember when first translating a bash script to babashka thinking cool, cool, cool - then, oh but that’s a bit of a big fn to just call a process, then, cool, cool, cool.
@lee fwiw, this was my fix for Windows: https://github.com/borkdude/babashka.curl/blob/53b5b9d98f2e594384f628b0deee76b53bea5062/src/babashka/curl.clj#L20
Oh, I think you have helped me see that my version is adding too many backslashes maybe.
With clj-kondo I applied the same: https://github.com/borkdude/clj-kondo/blob/de925fa93ede2672cba5de4d36cfd3c21e0a7f72/test/clj_kondo/test_utils.clj#L110
I'm still a bit unsure about some things: maybe :out :string
and :err :string
should be the default. And when it is, maybe :exit
should be the exit code directly, not a future / delay with an exit code. This is also how babashka.curl works. Also maybe throw with the contents of :err
if :exit
is non-zero, unless :throw
is false
.
yeah i like that paradigm
I’m a sample size of 1, but when scripting I only occasionally capture output to strings. So :out
and :err
defaulting to :inherit
would make more sense for me. My bash scripts always start with set -eou pipefail
meaning that when anything goes wrong, I’d like my script to fail, so a default of throwing on error in babashka would make sense for me. That said, if I don’t like the defaults, I can very easily write a little wrapper fn that changes them.
Added this now:
Both :in
and :out
may contain objects that are compatible with
:
clojure
user=> (with-out-str (process ["cat"] {:in "foo" :out *out*}))
"foo"
user=> (with-out-str (process ["ls"] {:out *out*}))
"LICENSE\nREADME.md\ndeps.edn\nsrc\ntest\n"