Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'modify': 0.04; 'that?': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'parameter:': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:variable': 0.16; 'subprocess': 0.16; 'subprocess,': 0.16; 'variable': 0.18; 'pass': 0.22; 'import': 0.24; 'header :User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'environment': 0.29; 'retain': 0.33; 'message-id:@gmail.com': 0.34; 'running': 0.34; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'environment.': 0.37; 'skip:e 20': 0.39; 'to:addr:python.org': 0.40; 'received:89': 0.80 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Akira Li <4kir4.1i@gmail.com> Subject: Re: Modify environment variable for subprocess Date: Thu, 24 Sep 2015 03:12:01 +0300 References: <6f8c6233-9777-488f-9026-fec729fef6d1@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain X-Gmane-NNTP-Posting-Host: 89.169.229.68 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:ZA3/1L912Vu+a97YXCj62H9tg5Y= 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: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1443053508 news.xs4all.nl 23837 [2001:888:2000:d::a6]:33786 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:97054 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? 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'))