babashka

Oliver Marks 2026-05-14T14:52:38.173689Z

I am trying to use psql in docker container, how ever using process I am seeing the stream is closed instantly and not available to write data into.

(do
    (def psql-proc (process ["docker" "exec" "-i" "88277e3d94ba" "psql"]
                            {:in :pipe :out :string :err :string
                      :pre-start-fn #(apply println "Running" (:cmd %))}))
    (with-open [w (io/writer (:in psql-proc))]
      (.write w "SELECT 1 as connection_test;\n")
      (.flush w)))
  ;; => java.io.IOException: Stream Closed load-data /home/user/tasks/load_data.clj:5:5
running the docker container in bash I can start typing in queries and see them in docker logs
echo "SELECT 1;" | docker exec -i 88277e3d94ba psql
I was expecting the same behavior when using process, my goal is to keep psql open while sending honeysql formatted sql strings into the process. Any idea where I could be going wrong ?

✅ 1
Oliver Marks 2026-05-15T19:28:49.058889Z

Awesome thanks @borkdude there was a couple of issues, I think the main one was I had the options the wrong side of the process function, also removed the :in :pipe and it all clicked into place, thanks for the assist :)

Crispin 2026-05-14T15:22:57.504029Z

Maybe try printing out your error string (:err psql-proc) there might be something in it that might help?

Oliver Marks 2026-05-14T15:36:47.982879Z

unfortunately its always blank, I tried a similar example with cat outside of docker and it seemed to work

Oliver Marks 2026-05-14T15:37:43.623479Z

using cat inside docker also works, so its something specific with psql

Oliver Marks 2026-05-14T15:37:57.794119Z

its like it not keeping the pipe open to send the data

borkdude 2026-05-14T16:14:21.932529Z

with-open closes the in stream

borkdude 2026-05-14T16:14:45.037329Z

could that be the issue?

borkdude 2026-05-14T16:16:25.641469Z

I don't think :in :pipe is a supported option in bb.process

borkdude 2026-05-14T16:16:31.580459Z

just leave that out

borkdude 2026-05-14T16:27:43.980999Z

also passing the string to :in would work

grzm 2026-05-14T18:17:39.981729Z

It might also be worth trying your psql invocation outside of the docker container to confirm whether it's docker or the code.

borkdude 2026-05-14T18:18:34.016849Z

or try another program like cat as well

borkdude 2026-05-14T18:39:03.862769Z

I spawned a psql instance in docker myself now. This works for me:

(require '[babashka.process :refer [process]])

(do
  (def psql-proc (process {:out :inherit :err :inherit}
                          "docker" "exec" "-i" "psql-repro"
                          "psql" "-U" "postgres" "-d" "testdb"))
  (with-open [w (io/writer (:in psql-proc))]
      (.write w "SELECT 1 as connection_test;\n")
    (.flush w)))

Harold 2026-05-14T16:12:09.032099Z

--- simple_smile Fun theory: coding assistants are better at babashka than clojure because they can 'think in bash and translate' and they are very, very good at bash.

😆 1
yannvahalewyn 2026-05-14T17:10:04.876629Z

impossible, no-one is good at bash!

😉 1
Harold 2026-05-14T17:47:48.452219Z

fairly sure bash is particularly well-represented in the training data. 🙂

cormacc 2026-05-14T21:26:14.892169Z

Bash is my love language - Claude loves it when we talk dir-tty

😂 4