python - 使用 bash 而不是 sh 作为 python 命令命名空间函数的首选 shell

标签 python bash shell

我需要使用适合 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/

相关文章:

linux - 记录终端命令

python - 重命名重复的索引值 pandas DataFrame

python - POSIX 到 Olson/IANA 时区格式转换

C UNIX Shell execvp 回显引号

linux curl 重定向和授权

linux - Bash 脚本运行带参数的程序不起作用

linux - Shellscript If 语句返回错误

python - 如何将外部 api 的响应传递到 Watson 对话中的对话框?

python - Keras fit_generator 运行速度非常慢

git - 带有 Git 当前分支和颜色的 PS1 行