user1506145 user1506145 - 1 month ago 4x
Node.js Question

NodeJS parse process.stdout to a variable

I am trying to read from stdout and put it to a variable in NodeJS. This is what I've tried:

process.stdout.on('data', function(data) {


I expect it to output hello two times, but it only outputs it one time. Why is the callback not triggered? It works when using stdin..


You are trying to use the Readable Stream API on a Writable Stream. Specifically, the process.stdout stream is for writing to stdout not reading from stdout. What you are trying to do isn't possible, would create an infinite loop if it did work, and breaks the definition of what stdin and stdout are.