What's the difference between subprocess.Popen(“echo $HOME”… and subprocess.Popen([“echo”, “$HOME”]

后端 未结 3 598
不知归路
不知归路 2021-01-15 08:38

I cannot get it it\'s bash related or python subprocess, but results are different:

>>> subprocess.Popen(\"echo $HOME\", shell=True, stdout=subproce         


        
3条回答
  •  一向
    一向 (楼主)
    2021-01-15 09:34

    When you have shell=True, actual process that runs is the shell process i.e., think of it running /bin/sh -c on unix. The arguments you pass to Popen are passed as arguments to this shell process. So /bin/sh -c 'echo' '$HOME' prints newline and the second argument is ignored. So usually you should only use string arguments with shell=True.

提交回复
热议问题