Using Python to automate builds

Gabriel Genellina gagsl-py2 at
Fri Aug 7 05:21:38 CEST 2009

En Thu, 06 Aug 2009 14:27:56 -0300, Kosta <kosta.koeman at>  
> On Aug 6, 3:57 am, David Cournapeau <courn... at> wrote:
>> On Thu, Aug 6, 2009 at 12:39 AM, Kosta<kosta.koe... at> wrote:
>> > Setenv.bat sets up the path and other environment variables build.exe
>> > needs to compile and link (and even binplace) its utilities.  So
>> > building itself is not the issue.  The problem is that if I call
>> > setenv.bat from Python and then build.exe, but the modifications to
>> > the path (and other environment settings) are not seen by Python, so
>> > the attempt to build without a specified path fails.
>> It sounds like you do not propagate the environment when calling
>> setenv.bat from python. There is an option to do so in
>> subprocess.Popen init method, or you can define your own environment
> My interpretation of the above (and your email) is that using Popen
> allows one to pass the Python environment to a child processs (in my
> case, setenv.bat).   I need the reverse, to propagate from the child
> to the parent.

In addition to just calling setenv, dump the modified environment. Parse  
the output into a dictionary that you can use as the env argument to later  
subprocess calls:

py> import subprocess
py> cmdline = '(call setenv >nul 2>&1 & set)'
py> p = subprocess.Popen(cmdline, stdout=subprocess.PIPE, shell=True)
py> env = dict(line.rstrip().split("=",1) for line in p.stdout)
py> p.wait()
py> env
{'TMP': 'D:\\USERDATA\\Gabriel\\CONFIG~1\\Temp', 'COMPUTERNAME': 'LEPTON',  
'HOMEDRIVE': 'D:', ...
py> env['FOO']='Salta Violeta!'
py>"echo %FOO%", shell=True, env=env)
Salta Violeta!

Gabriel Genellina

More information about the Python-list mailing list