nbb

sirwobin 2023-06-03T10:46:44.137069Z

How should I register to listen for socket events coming from a child process stdout?

sirwobin 2023-06-03T10:47:36.386999Z

(ns blah
  (:require ["node:child_process" :as child-process])

(let [cp (.spawn child-process "ls" ["-l"])]
  (-> cp .stdout (.on "data" (fn [data]...))

sirwobin 2023-06-03T10:50:05.447649Z

running something like that gives me error Function.prototype.apply was called on #<Socket>, which is a object and not a function

borkdude 2023-06-03T11:31:08.221089Z

Shouldn't ["ls"] be #js ["ls"]? Not sure if that matters

🙏 1
borkdude 2023-06-03T11:33:39.687829Z

This works:

(ns blah
  (:require ["node:child_process" :as child-process]))

(let [cp (child-process/spawn "ls" #js ["-l"])]
    (-> cp .-stdout (.on "data" (fn [data] (prn data)))))

borkdude 2023-06-03T11:33:48.173259Z

So instead of .stdout write .-stdout

🙏 1
sirwobin 2023-06-03T12:19:18.924179Z

Oh course! Thanks for pointing that out. 🙂