我需要使用适合 bash 风格的命令行,例如
diff x <(cat y | tail +2)
但是,上述行的 sh -c 给出了错误,因此上述行的commands.getoutput 失败。 然而,上面的 bash -c 做了我想要完成的事情。有人可以建议如何让 python 使用 bash 吗? 我知道我可以使用子进程来完成它,但是我有很多必须处理的命令行,并且我只想使用commands.getoutput。
谢谢。
最佳答案
你可以做commands.getoutput("bash -c 'diff x <(tail +2 y)'")
,也许(请注意 cat
是不必要的)。
但是:commands.getoutput('tail +2 y | diff x -')
不需要 Bash。
关于python - 使用 bash 而不是 sh 作为 python 命令命名空间函数的首选 shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5044534/