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?

3
  • 1
    Is your child process attached to stdin? Post a full working example. Commented Mar 18 at 21:41
  • Thanks for a lead, I had stdio config for stdin as "inherit", so changing this fixes my issue, I still wonder, why "inherit" consumes every other key. Commented Mar 19 at 9:24
  • Because both processes are reading stdin. So one process reads on the first chart, the other the second char. I guess some kind of "race condition" Commented Mar 19 at 9:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.