Activating Batch Files from Python

Serge Orlov Serge.Orlov at gmail.com
Wed Apr 19 03:07:00 EDT 2006


Jeff Groves wrote:
> I'm writing a launcher that should do the following:
>
> 1. Activate a .bat file to set environmental variables.
> 2. Start 3 programs, using said environmental variables as arguments.
>
> However, I can't get the environmental variables to stick because all
> of Pythons' system start/open functions split off into their own little
> subshells, therefore the .bat file doesn't affect the main shell.

That's right. That is how enviromental variables work regardless of
programming language.

>
> How can I use the .bat file to set environmental vars from Python?

If it is your bat file, forget about it. Set the variables in your
Python program using os.environ. If it is a 3rd party bat file, the
best you can do is to copy it, add (at the end) a command to dump all
enviromental variables to a temp file like this: set >dump_file.txt,
parse the dump file to see what variables changed and set the variables
using os.environ.




More information about the Python-list mailing list