I use node.js and read the input from the serial port, opening the file / dev / tty, I send the command and read the result of the command, and I want to close the stream after I read and analyze all the data. I know that I have finished reading data with a data marker and ending it. I found that as soon as I closed the thread, my program would not exit.
The following is an example of what I see, but uses / dev / random to generate data slowly (assuming your system does little). I find that the process will end as soon as the device generates data after the stream closes.
var util = require('util'),
PassThrough = require('stream').PassThrough,
fs = require('fs');
var readStream = fs.createReadStream('/dev/random');
var pt = new PassThrough();
pt.on('data', function (data) {
console.log(data)
console.log('closing');
readStream.close();
});
readStream.pipe(pt);
Update: 1
, pty node. 2 pty , node, createReadStream.
var fs = require('fs');
var rs = fs.createReadStream('/dev/pts/1');
process.exit(0);
node . 10.28.