Skip to content
0

stdio

包括 stdinstdoutstderr.

结构

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: world

Also, 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)

Released under the MIT License.