This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-10
Channels
- # announcements (2)
- # asami (2)
- # babashka (29)
- # beginners (115)
- # cider (5)
- # clara (9)
- # cljdoc (14)
- # cljs-dev (1)
- # cljsrn (18)
- # clojars (3)
- # clojure (73)
- # clojure-australia (7)
- # clojure-europe (74)
- # clojure-nl (3)
- # clojure-norway (8)
- # clojure-spec (3)
- # clojure-uk (36)
- # clojured (1)
- # clojurescript (15)
- # conjure (18)
- # datomic (6)
- # deps-new (11)
- # depstar (7)
- # fulcro (2)
- # instaparse (1)
- # jobs (9)
- # nrepl (8)
- # off-topic (21)
- # pathom (5)
- # polylith (42)
- # proletarian (1)
- # rdf (10)
- # re-frame (2)
- # react (1)
- # reagent (20)
- # releases (3)
- # remote-jobs (4)
- # rum (9)
- # shadow-cljs (79)
- # sql (11)
- # tools-deps (64)
- # vim (3)
- # xtdb (26)
New babashka release: 0.4.5
Babashka proper:
- Add java.net.InetSocketAddress
- Add support for slingshot https://github.com/babashka/babashka/issues/675
- Add STM facilities (`dosync`, ref
, etc.)
- Fix .wait
, .notify
interop on arbitrary classes
Deps.clj (used for resolving deps and clojure
invocations):
- Fix JVM option parsing https://github.com/borkdude/deps.clj/issues/46
Sci: various minor performance improvements.
https://github.com/babashka/babashka/blob/master/CHANGELOG.md#045

I'm a real noob at bb, and at running "imperative" commands from clj at all. How would you structure a pretty simple script that is supposed to do about this thing, here in zsh loop:
for i in `seq 1 100`; do
echo $i >> main.go
git add .
git commit -m $i
;done
@emilaasa for
translates to doseq
in clojure (used for side effects. seq 1 100
is (range 1 100)
(not sure about inclusive/exclusive in bash).
The echo call can be done using (spit "main.go" i :append true)
Calling git can be done using shelling out e.g. with clojure.java.shell
or babashka.process
or in tasks using shell
Ah great it works exactly the same with waiting for shell output and everything!
(doseq [i (range 100)]
(append-to-file "main.go" (gofunc (str "funfunc" i)))
(gofmt "main.go")
(add "main.go")
(commit "asdf"))
I am still unable to capture stderr in babashka/process:
(require '[babashka.process :as p :refer [process]]
'[ :as io])
(def c (process ["bash" "-c" "echo An error message > /dev/stderr"] {:err :inherit :shutdown p/destroy}))
(with-open [rdr (io/reader (:out c))]
(binding [*in* rdr]
(loop []
(let [line (read-line)]
(println :line line)
(when (not (nil? line))
(recur))))))
prints
An error message
:line nil
I was expecting
:line An error message
:line nil
Any hints?Can you reproduce? This happens in both the rebl and the cider repls.
But does not :inherit
merge the two?
The name is adopted from the Java API: https://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html#inheritIO()
This works:
(require '[babashka.process :as p :refer [process]]
'[ :as io])
(def c (process ["bash" "-c" "echo An error message > /dev/stderr"]
{:shutdown p/destroy}))
(with-open [rdr (io/reader (:err c))]
(binding [*in* rdr]
(loop []
(let [line (read-line)]
(println :line line)
(when (not (nil? line))
(recur))))))
I see. redirectErrorStream
is perhaps what I want: https://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html#inheritIO()
But it might be nice to be able to distinguish stderr and stdout also. Is there a way to read both at the same time? Thanks for the help btw!
I will try. I'd imagine one would have to finish before the other begins, but I'll test it out.
That is what I did 🙂 (.start (Thread. my-loop))
. I'm used to multithreading stuff being such a pain in the behind. That seems to be one aspect of the language which is easier in Java than in Python