Fork me on GitHub
#babashka
<
2020-12-28
>
benny17:12:58

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?

borkdude17:12:36

@b can you make a repro

benny17:12:02

@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

borkdude17:12:01

@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

benny17:12:44

yeah :inherit true also works, I want to capture the stdout and act on the different lines, like a real time log reader

borkdude17:12:04

@b there might be some relevant things here: https://book.babashka.org/#child_processes

benny17:12:43

it seems like edn/read is the magic there, I will just try around some more with the java interop

borkdude18:12:44

@b you can also use (binding [*in* (:out process)] (read-line))

borkdude18:12:52

in a loop and in a future for example

benny18:12:18

@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)

borkdude18:12:52

@b in that case process is (process ["yes"]) without any options

borkdude18:12:06

this will give you the raw stream

borkdude18:12:59

@b sorry, like this:

user=> (def yes (babashka.process/process ["yes"]))
#'user/yes
user=> (binding [*in* (io/reader (:out yes))] (read-line))
"y"

borkdude18:12:14

*in* should always be bound to a reader

benny19:12:50

@borkdude Thanks! this works great! 🙂

👍 1