SBoudrias / Inquirer.js

A collection of common interactive command line user interfaces.
MIT License
20.34k stars 1.31k forks source link

Prompt confirm does not work with yes unix command #365

Open ransombriggs opened 8 years ago

ransombriggs commented 8 years ago

When inquirer prompts are used and stdin is not a tty, the prompt hangs as long as stdin is still open. We recently started using inquirer and found that one of our users has been piping in yes into one of commands to confirm all the prompts and was confused when nothing happened. I have included an extracted example to show the behavior.

'use strict';

let inquirer = require('inquirer');
inquirer.prompt([{
  type: 'confirm',
  name: 'yes',
  message: 'Hello World?'
}]).then(function(resp) {
  console.log(resp);
});

The y line is read, the problem is that the promise never fullfills so long as there is input on stdin.

-> % yes | node prompt.js
? Hello World? Yes
y
y
y
y
y
y
y
y
y
y
y
y
y
y
y
y
y
(...)
jdx commented 8 years ago

@hone mentioned a lot of Docker users like to use yes |, so it would be great if this worked!

jdx commented 8 years ago

Looks like this does work with inquirer 0.x but not 1.x with this code:

'use strict';

let inquirer = require('inquirer');
inquirer.prompt([{
  type: 'confirm',
  name: 'yes',
  message: 'Hello World?'
}], (resp) => console.log(resp))
$ yes | node inquirer-test.js
SBoudrias commented 8 years ago

@dickeyxxx inquirer relies on the readline. Usually input is read once we reach an end of line marker, and from what I see, this should occurs using yes. I'll see if I have time to investigate further, but to be fair that's not exactly taking top priority on my bug list.

johannesjo commented 8 years ago

Same issue here.

anortef commented 8 years ago

This is very annoying when scripting to be honest.

noel-yap commented 7 years ago

I'm running into this issue as well.

fearphage commented 7 years ago

I cannot confirm. Master and the latest release are working flawlessly as best I can tell.

➜  Inquirer.js git:(master) yes | node test-confirm.js
? Hello World? Yes
{ yes: true }
➜  Inquirer.js git:(master) gco -q v3.0.6
➜  Inquirer.js git:(6fa4610) yes | node test-confirm.js
? Hello World? Yes
{ yes: true }

Update your version of the library?

EDIT: I'm using the same code as above.

elclanrs commented 7 years ago

I'm experiencing the same issue. yes accepts the confirm, but then it prints y forever, it doesn't actually exit the script.