在交互式脚本中使用yes会导致退出代码141

时间:2018-11-02 21:33:16

标签: bash printf circleci

我需要在CircleCI中运行一个命令,该命令会将预定的参数传递给以下命令。当命令只需要字符串或整数时,可以很好地使用:

printf "arg1\narg2\n" | my_command

但是,如果“我的命令”希望用户使用箭头键选择一个选项,然后再使用返回键,则此方法将失败。

以下是我所描述的示例:

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

所以我尝试了另一种选择,找到了一个不错的工具yes:

yes | my_command

这实际上可以工作(并选择选项A),但是由于退出代码141,这会导致CircleCI生成失败。据我了解,退出代码的发生是因为yes仍在将输入发送到具有退出。

还有另一种方法可以完成吗?

3 个答案:

答案 0 :(得分:0)

您可以尝试expect-使用交互式程序进行的编程对话

答案 1 :(得分:0)

通过使用双管道设置为true,我能够覆盖该错误。

yes | my_command || true

这有效,但它会覆盖序列可能引发的任何错误,从而使我的CI测试常绿。这不理想,但是可以。

答案 2 :(得分:0)

selection = cmds.ls(sl=True, o=True)[0]    
faces = cmds.ls(sl=True)
x = 0
# assign shader
sha = cmds.shadingNode('lambert', asShader=True, name="{}_{}_lambert".format(selection, x))
sg = cmds.sets(empty=True, renderable=True, noSurfaceShader=True,  name="{}_{}_sg".format(selection, x))
cmds.connectAttr( sha+".outColor", sg+".surfaceShader", f=True)
cmds.sets(faces, e=True, forceElement=sg)

这样,您将忽略(yes || true) | my_command 中的结果代码,但保留yes中的结果代码。