【发布时间】:2012-11-10 18:37:40
【问题描述】:
我无法在 CentOS 中使用 python 2.7 打开 bash shell,我可以在 python 2.6.6 Debian 中这样做。发生了什么变化?
我尝试了一个简单的 bash 进程替换:
from subprocess import Popen
cmd="""cat <<'EOF'
this is
test $unchanged
EOF
"""
Popen('cat <(%s)' % cmd, shell=True, executable='/bin/bash')
在 Debian 中有效,在 CentOS 中无效:
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `cat <(cat <<'EOF''
区别在于:
-
Debian:Python 2.6.6,
/bin/sh由 dash 提供。 -
CenOS(Red Hat):Python 2.7,
/bin/sh由 bash 提供
所以在 CentOS 中,executable=/bin/bash 根本不被尊重。
我错过了什么吗?
【问题讨论】:
-
尝试将
cat <(%s)' % cmd替换为cmd。 -
@werehuman 这是测试 bash 是否正在启动,
sh可以进行重定向,但不能处理替换,我需要一些不同的东西。 -
好吧,如果你在参数中写 /bin/bash 呢?
Popen(['/bin/bash', '-c', 'cat <(%s)' % cmd]) -
@werehuman 确实有效!这就是执行标志应该做的......不知道为什么不是
-
我没有 CentOS 机器,但我认为 bash 有问题。
标签: python bash centos debian redhat