Han*_*Sun 7 python shell subprocess
我想知道是否subprocess.call("if [ ! -d '{output}' ]; then mkdir -p {output}; fi",shell=True)会被不同的服务器解释sh或zsh代替bash?
有人有这方面的想法吗?
我该怎么做以确保它被解释bash?
Pav*_*sov 25
http://docs.python.org/2/library/subprocess.html
Run Code Online (Sandbox Code Playgroud)On Unix with shell=True, the shell defaults to /bin/sh
请注意,/ bin/sh通常符号链接到不同的东西,例如在ubuntu上:
$ ls -la /bin/sh
lrwxrwxrwx 1 root root 4 Mar 29  2012 /bin/sh -> dash
您可以使用executable参数替换默认值:
...如果shell = True,则在Unix上,executable参数指定默认/ bin/sh的替换shell.
subprocess.call("if [ ! -d '{output}' ]; then mkdir -p {output}; fi",
                shell=True,
                executable="/bin/bash")