Python Popen can't open bash shell in CentOS/Red Hat

≯℡__Kan透↙ 提交于 2019-12-12 04:42:51

问题


I can't open a bash shell in CentOS with python 2.7, I'm able to do so in python 2.6.6 Debian. What has changed?

I tried a simple bash process substitution:

from subprocess import Popen
cmd="""cat <<'EOF'
this is
test $unchanged
EOF
"""
Popen('cat <(%s)' % cmd, shell=True, executable='/bin/bash')

In Debian this works, in CentOS it doesn't:

/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `cat <(cat <<'EOF''

The differences are:

  • Debian: Python 2.6.6, /bin/sh is provided by dash.
  • CenOS (Red Hat): Python 2.7, /bin/sh is provided by bash

So in CentOS the executable=/bin/bash is not being honored at all. Am I missing something?


回答1:


What if you write /bin/bash in arguments?

Popen(['/bin/bash', '-c', 'cat <(%s)' % cmd])


来源:https://stackoverflow.com/questions/13511422/python-popen-cant-open-bash-shell-in-centos-red-hat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!