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 ?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 :)
Maybe try printing out your error string (:err psql-proc) there might be something in it that might help?
unfortunately its always blank, I tried a similar example with cat outside of docker and it seemed to work
using cat inside docker also works, so its something specific with psql
its like it not keeping the pipe open to send the data
with-open closes the in stream
could that be the issue?
I don't think :in :pipe is a supported option in bb.process
just leave that out
also passing the string to :in would work
It might also be worth trying your psql invocation outside of the docker container to confirm whether it's docker or the code.
or try another program like cat as well
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)))--- 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.
impossible, no-one is good at bash!
fairly sure bash is particularly well-represented in the training data. 🙂
Bash is my love language - Claude loves it when we talk dir-tty