Python subprocess/Popen with a modified environment

前端 未结 8 796
再見小時候
再見小時候 2020-11-22 14:06

I believe that running an external command with a slightly modified environment is a very common case. That\'s how I tend to do it:

import subprocess, os
my_         


        
8条回答
  •  情书的邮戳
    2020-11-22 14:40

    The env parameter accepts a dictionary. You can simply take os.environ, add a key (your desired variable) (to a copy of the dict if you must) to that and use it as a parameter to Popen.

提交回复
热议问题