Path: csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'modify': 0.04; 'that?': 0.05; 'leaks': 0.09; 'os.environ': 0.09; 'received:openend.se': 0.09; 'received:theraft.openend.se': 0.09; 'wed,': 0.15; 'from:addr:lac': 0.16; 'from:addr:openend.se': 0.16; 'from:name:laura creighton': 0.16; 'message-id:@fido.openend.se': 0.16; 'received:fido': 0.16; 'received:fido.openend.se': 0.16; 'subject:variable': 0.16; 'subprocess,': 0.16; 'memory': 0.17; 'laura': 0.18; "shouldn't": 0.18; 'variable': 0.18; '2015': 0.20; 'skip:" 30': 0.20; 'sep': 0.22; 'import': 0.24; '-0700,': 0.29; 'received:se': 0.29; 'environment': 0.29; 'retain': 0.33; 'running': 0.34; 'add': 0.34; 'something': 0.35; 'problem.': 0.35; 'but': 0.36; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'setting': 0.37; 'environment.': 0.37; 'mac': 0.37; 'charset:us-ascii': 0.37; 'means': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'header:Message-Id:1': 0.61; 'times': 0.63; 'header:In-reply-to:1': 0.84 to: python-list@python.org From: Laura Creighton Subject: Re: Modify environment variable for subprocess In-reply-to: <6f8c6233-9777-488f-9026-fec729fef6d1@googlegroups.com> References: <6f8c6233-9777-488f-9026-fec729fef6d1@googlegroups.com> Comments: In-reply-to loial message dated "Wed, 23 Sep 2015 02:51:53 -0700." MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <5089.1443004643.1@fido> Content-Transfer-Encoding: quoted-printable Date: Wed, 23 Sep 2015 12:37:23 +0200 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (theraft.openend.se [82.96.5.2]); Wed, 23 Sep 2015 12:37:24 +0200 (CEST) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1443004647 news.xs4all.nl 23840 [2001:888:2000:d::a6]:44643 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:97034 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 =3D os.environ # if your program should be able to modify the curr= ent env # otherwise my_env =3D os.environ.copy() # if it shouldn't # if you just want to add something to the existing LIBPATH my_env["LIBPATH"] =3D "/where/I/want/to/look/first:" + my_env["LIBPATH"] # otherwise my_env["LIBPATH"] =3D "/what/I/want" subprocess.Popen(my_program, env=3Dmy_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