Python: Exporting environment variables in subprocess.Popen(..)

后端 未结 3 1775
死守一世寂寞
死守一世寂寞 2020-11-30 11:06

I am having an issue with setting an environment variable on a call to subprocess.Popen. The environment variable does not seem to be getting set. Any suggestio

3条回答
  •  無奈伤痛
    2020-11-30 11:17

    For Python 3.5 and newer, you can use unpacking generalizations, eg:

    env = {
        **os.environ,
        "TEST_VARIABLE": str(1234),
    }
    subprocess.Popen('/usr/bin/mybinary', env=env).wait()
    

提交回复
热议问题