uiop:launch-program and nodejs

Viewed 68

I'm trying to launch node, write JS and read back the answer. Why does the following code not work but hangs at the read-line? echo "console.log(1+1)" | node works fine.

(defvar node-process (uiop:launch-program '("/usr/local/bin/node")
                                          :input :stream
                                          :output :stream
                                          :error-output :stream))

(defvar node-stream (make-two-way-stream (uiop:process-info-output node-process)
                                         (uiop:process-info-input node-process)))

(write-line "console.log(1+1)" node-stream)
(force-output node-stream)
(format t "~s~%" (read-line node-stream))
1 Answers

It appears that node only emit output after EOF is read when in non-interactive mode, so you need to close the input stream before reading.

Add (close (two-way-stream-input-stream node-stream)) after force-output and before read-line.

Related