babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
benny 2020-12-28T17:34:58.408700Z

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?

borkdude 2020-12-28T17:39:36.409Z

@b can you make a repro

benny 2020-12-28T17:45:02.411600Z

@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

borkdude 2020-12-28T17:46:01.412400Z

@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

benny 2020-12-28T17:46:44.413200Z

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

borkdude 2020-12-28T17:53:04.414200Z

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

benny 2020-12-28T17:58:43.414900Z

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

borkdude 2020-12-28T18:00:44.415600Z

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

borkdude 2020-12-28T18:00:52.415800Z

in a loop and in a future for example

benny 2020-12-28T18:08:18.416600Z

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

borkdude 2020-12-28T18:37:52.417400Z

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

borkdude 2020-12-28T18:38:06.417700Z

this will give you the raw stream

borkdude 2020-12-28T18:41:59.418Z

@b sorry, like this:

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

borkdude 2020-12-28T18:42:14.418200Z

*in* should always be bound to a reader

benny 2020-12-28T19:16:50.418600Z

@borkdude Thanks! this works great! 🙂

👍 1