如何在 python sh 中为命令添加尾部破折号(以允许命令使用标准输入)

How to have trailing dash to command (to allow command to consume stdin) in python sh

我该如何转换它: echo -e 'FROM busybox\nRUN echo "hello world"' | docker build -

转换为 sh (https://github.com/amoffat/sh) 语法。

我遇到的问题是 args 被标记化并被引用。因此 docker 无法将 stdin 传递到命令的末尾,因为 - 在其周围放置了单引号。在文档中挖掘我没有看到支持这个的方法。

感谢您提供的任何帮助(或者,如果您有在子流程中执行此操作的良好示例,那也行得通。)!

The issue I have is that the args are tokenized and quoted. So docker isn't able to pass stdin onto the end of the command since - has single quotes placed around it.

就像我评论的那样,

- isn’t special shell syntax. It should work fine as a normal argument.

不过,根据文档,您看起来是这样操作的。使用 _in

dockerfile = r"""
FROM busybox
RUN echo "hello world"
"""

docker.build("-", _in=dockerfile)