I'm trying to use babashka.process to watch a child process and for some reason I'm unable to use an io/reader to read from it (thus blocking the spawned process, as it stop acting when it can't flush the stdout), is there some example code somewhere that handles a streaming process?
@b can you make a repro
@borkdude I can't think of an easy way, it's a process that stops acting when you don't read its stdout... something like "yes" would probably also only fill the cache but there is no accompanying counter to visualize this
@b Yes, a process has a limited buffer, so you can use a StringWriter as :out
for example to let it write to stdout in an unlimited fashion
yeah :inherit true
also works, I want to capture the stdout and act on the different lines, like a real time log reader
@b there might be some relevant things here: https://book.babashka.org/#child_processes
it seems like edn/read is the magic there, I will just try around some more with the java interop
@b you can also use (binding [*in* (:out process)] (read-line))
in a loop and in a future for example
@borkdude I'm a bit lost, what is process in that situation? (p/process ["yes"] {:inherit true})
? or in combination with :out StringWriter (which I have to look up how that gets initalized)
@b in that case process is (process ["yes"])
without any options
this will give you the raw stream
@b sorry, like this:
user=> (def yes (babashka.process/process ["yes"]))
#'user/yes
user=> (binding [*in* (io/reader (:out yes))] (read-line))
"y"
*in*
should always be bound to a reader
@borkdude Thanks! this works great! 🙂