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?