Modify environment variable for subprocess

Akira Li 4kir4.1i at gmail.com
Wed Sep 23 20:12:01 EDT 2015


loial <jldunn2000 at gmail.com> 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