Modify environment variable for subprocess

Akira Li 4kir4.1i at
Thu Sep 24 02:12:01 CEST 2015

loial <jldunn2000 at> writes:

> I need to modify the LIBPATH environment variable when running a
> process via subprocess, but otherwise retain the existing environment.
> Whats the best way to do that?

Pass env=dict(os.environ, LIBPATH=value) parameter:

  import os
  import subprocess 
  subprocess.check_call('echo $LIBPATH', shell=True,
                        env=dict(os.environ, LIBPATH='/some/path'))

More information about the Python-list mailing list