Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Will not work in Bash command when information piped in #40

Open
guypursey opened this issue Apr 26, 2020 · 1 comment
Open

Will not work in Bash command when information piped in #40

guypursey opened this issue Apr 26, 2020 · 1 comment

Comments

@guypursey
Copy link

To recreate, create the following file prompt-test.js, as a very simple test:

#!/usr/bin/env node
const prompt = require("prompt-sync")({"sigint": true})

for (var i = 0; i < 5; i++) {
  console.log("Before prompt line")
  var result = prompt("This is a test -- enter something >");
  console.log("Result of prompt", result)
}

If run as ./prompt-test.js, it will ask for an input 5 times and print that output as you might expect.

However if you trying running echo hello world | ./prompt-test.js, the prompt itself is caught in a loop and repeats the prompt line and all previous inputs continually.

This might be happening because of my lack of understanding about Bash processes, sub-processes, or piping. Any help appreciated.

@guypursey
Copy link
Author

guypursey commented May 2, 2020

This might have something to do with the reliance on process.stdin ... code suggests that's being used when process.platform === 'win32'. From the little I know, if a TTY readstream can be used instead, for example, it means piped input and keyboard input can be accepted and should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant