Reputation: 51
Im using Ubuntu 20 with zsh. When I using subprocess.call, it always using bash to exec command but not zsh. How should I do to fix this?
Upvotes: 1
Views: 2842
Reputation: 189749
No, it uses sh
regardless of which shell is your login shell.
There is a keyword argument to select a different shell, but you should generally run as little code as possible in a subshell; mixing nontrivial shell script with Python means the maintainer has to understand both languages.
whatever = subprocess.run(
'echo $SHELL',
shell=True, executable='/usr/bin/zsh',
check=True)
(This will echo your login shell, so the output would be /usr/bin/zsh
even if you ran this without executable
, or with Bash instead.)
In many situations, you should avoid shell=True
entirely if you can.
Upvotes: 1