0

Hi I have written this program with inquirer.js it has a list question and after that a text input.

I want to answer both questions with piping.

If I just keep the list question, I can easily use yes 1 | command and it selects the first option and I'm done.

But keeping both questions same command passes the first question just fine but on the text one it would keep blinking 1 forever.

Using echo "something" | command surprisingly selects default on the first question and leaves the second one alone, though it doesn't wait for user input it's like it has inputted nothing in there but has pressed enter for both questions really weird.

Using yes '' | command doesn't get stuck and behaves exactly as above example.

Using yes '1\nhello\n' | command answers the first question fine and the second question keeps blinking between 1 and hello forever.

I have no other idea what to do now. Any help would be appreciated.

Steve Moretz
  • 101
  • 2
  • re. `echo "something" | command` acting weird, you'll have to look inside the program to see how it deals with the input it gets. E.g. if it expects a number, and reads any digits it finds, leaving the rest in the input buffer, then it would use the rest as an answer to the second question. (That's what you'd get in C with `scanf()`, which makes it horrible for interactive input.) You might also want to consider changing from interactive questioning to using command line arguments. – ilkkachu Apr 27 '22 at 22:55
  • @roaima sorry you are right updated. – Steve Moretz Apr 28 '22 at 05:34
  • @ilkkachu that's a good idea thank you! – Steve Moretz Apr 28 '22 at 05:35
  • Following on from Ilkkachu's suggestion, if you want to keep the interactive aspect then allow both. No command line parameters => interactive session. Otherwise get the selections from the command line – roaima Apr 28 '22 at 05:55
  • @roaima that is a good idea, however my purpose only is just to run some tests with a testing library. but that's a great idea if you really need both! – Steve Moretz Apr 28 '22 at 06:55
  • I just noticed yes "s\n2\n" actually prints `s\n2\n` on each line!! $'s\n2\n' works but no difference in the program behavior nevermind. – Steve Moretz Apr 28 '22 at 07:45

0 Answers0