Node.js Write To Child Process
Solution 1:
The EPIPE
write error means someone is writing into a pipe that no one will ever read from.
Additionally, because this error is being raised in a context where no one handles it, the error is fatal for your process. Sadly, node doesn't do a good job of identifying which stream, but we can guess that its in your code, and there is only one stream being written to by this code ...
You can verify that the error is coming from the "stdin" stream if you add an error handler:
test.stdin.on('error', (...args) => { console.log('stdin err', args); });
Now the error will be "handled" (poorly), and the process will continue, so you at least know where its coming from.
Specifically this test.stdin.write('q')
is writing a q
to the stdin of your process. But your child process is ls
. It doesn't accept anything on stdin, so it closes stdin. So the OS sends an EPIPE error back when the parent tries to write to the now-closed pipe. So, stop doing that.
You probably expect ls
to behave the same as when you type ls
interactively, but it probably does not (I suspect your interactive ls
is going through a pager, and you're expecting that you need to quit that pager?) This child process is more equivalent to running /bin/ls
interactively.
Post a Comment for "Node.js Write To Child Process"