Using yes with interactive script results in exit code 141

Viewed 1430

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?

3 Answers
(yes || true) | my_command

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

You can try expect - programmed dialogue with interactive programs

I was able to override the error by using double pipes to true.

yes | my_command || true

This works but it overrides any errors that the sequence might throw, making my CI tests evergreen. Which is not ideal, but it works.

Related