nbb 2023-06-03

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

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

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

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

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

🙏 1

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

So instead of .stdout write .-stdout

🙏 1

Oh course! Thanks for pointing that out. 🙂