stdio
包括 stdin、stdout、stderr.
结构
stdio in process
We can access stdio in Nodejs process.
process.stdin means input of process. So if we try to log process.stdin:
// index.ts
process.stdin.on('data', chunk => {
console.log('recive stdin chunk: ' chunk)
})The data output in the terminal will be same as our input:
hello # handle input
recive stdin chunk: hello
world # handle input
recive stdin chunk: worldAlso, we can write chunk by write method:
process.stdin.setEncoding('utf-8').on('data', data => {
console.log('get stdin', data)
})
let count = 0
setInterval(() => {
process.stdin.write(count.toString())
count++
}, 1000)