Fork me on GitHub
#nbb
<
2023-06-03
>
sirwobin10:06:44

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

sirwobin10:06:36

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

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

sirwobin10:06:05

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

borkdude11:06:08

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

🙏 2
borkdude11:06:39

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

borkdude11:06:48

So instead of .stdout write .-stdout

🙏 2
sirwobin12:06:18

Oh course! Thanks for pointing that out. 🙂