0

I have the following read/write nodejs application:

const readline = require('readline');

const readStream = process.stdin
const writeStream = process.stdout

const readInterface = readline.createInterface({
    input: readStream,
    output: writeStream,
    console: false
});

readInterface.on('line', async function(line) {
    readStream.write(line)
    console.log('line: ');
    console.log(line);
});

console.log(process.pid);

And I'm trying to read and write to the stdin and stdout process, respectively, through the process ID (PID), with these commands, on linux:

Reading from process stdout: tail -f /proc/<pid>/fd/1 or sudo cat /proc/<pid>/fd/1

Writing to process stdin: echo "test" > /proc/<pid>/fd/0

But it doesn't work. When I try to write in stdin the data sent appears on the application's terminal but the .on('line') event is not triggered. So how nodejs works with stdin, stdout and stderr files?

enter image description here

Jeff Pal
  • 1,227
  • 1
  • 12
  • 21
  • Does this answer your question? [How to write data to existing process's STDIN from external process?](https://stackoverflow.com/questions/5374255/how-to-write-data-to-existing-processs-stdin-from-external-process) – poida Nov 01 '21 at 23:40

0 Answers0