Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using yes with interactive script results in exit code 141

I need to run a command in CircleCI that will pass predetermined arguments to a following command. When the command only expects strings or integers it works fine to use:

printf "arg1\narg2\n" | my_command

But if "my command" expects a user to use arrow keys to select an option followed by the return key this method fails.

Here is an example of what I am describing:

? Which variation would you like to apply? (Use arrow keys)
❯ A
  B
  C

So I tried another option, having found a nifty tool called yes:

yes | my_command

This will actually work (and selects option A), but it results in a failed build in CircleCI due to the exit code 141. From what I understand, that exit code happens because yes is still sending input to a process that has exited.

Is there another way I can accomplish?

like image 377
Mike Fleming Avatar asked Jul 11 '26 11:07

Mike Fleming


1 Answers

(yes || true) | my_command

This way you ignore the result code from yes but preserve the result code from my_command.

like image 157
MentalPower Avatar answered Jul 13 '26 16:07

MentalPower



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!