最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - Reading user input while long running child process is running - every other key is missing - Stack Overflow

programmeradmin4浏览0评论

I have a simple Node CLI app that runs a long-running process, in this case a Gradle in watch mode.

I need to have some user control so I added a fairly standard setup for reading the keys like this:

process.stdin.setRawMode(true);
process.stdin.resume();

process.stdin.on('data', (key: Buffer) => {
    console.log('Key pressed:', key.toString());

    if (key.toString() === '\u0003') { 
        process.exit();
    }
});

The issue here is that in this scenario only every other key is actually read, starting second press, the rest is missing.

This only happens when the child process is started, otherwise all the keys are read normally. What is the cause of this? How can this be solved?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论