Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97034
| From | Laura Creighton <lac@openend.se> |
|---|---|
| Subject | Re: Modify environment variable for subprocess |
| References | <6f8c6233-9777-488f-9026-fec729fef6d1@googlegroups.com> |
| Date | 2015-09-23 12:37 +0200 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.99.1443004647.28679.python-list@python.org> (permalink) |
In a message of Wed, 23 Sep 2015 02:51:53 -0700, loial 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? import subprocess, os my_env = os.environ # if your program should be able to modify the current env # otherwise my_env = os.environ.copy() # if it shouldn't # if you just want to add something to the existing LIBPATH my_env["LIBPATH"] = "/where/I/want/to/look/first:" + my_env["LIBPATH"] # otherwise my_env["LIBPATH"] = "/what/I/want" subprocess.Popen(my_program, env=my_env) Setting os.environ leaks memory under Mac OS and FreeBSD. I am not sure if this means that if you do this a gazillion times on a Mac you will have a problem. Laura
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Modify environment variable for subprocess loial <jldunn2000@gmail.com> - 2015-09-23 02:51 -0700 Re: Modify environment variable for subprocess Cameron Simpson <cs@zip.com.au> - 2015-09-23 20:00 +1000 Re: Modify environment variable for subprocess Laura Creighton <lac@openend.se> - 2015-09-23 12:37 +0200 Re: Modify environment variable for subprocess Akira Li <4kir4.1i@gmail.com> - 2015-09-24 03:12 +0300
csiph-web