Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > subprocess & shared environments

Reply
Thread Tools

subprocess & shared environments

 
 
Robert Dailey
Guest
Posts: n/a
 
      05-01-2009
I'm currently calling subprocess.call() on a batch file (in Windows)
that sets a few environment variables that are needed by further
processes started via subprocess.call(). How can I persist the
environment modifications by the first call() function? I've done my
own searching on this and I came up with nothing.

Help is appreciated.
 
Reply With Quote
 
 
 
 
Piet van Oostrum
Guest
Posts: n/a
 
      05-01-2009
>>>>> Robert Dailey <> (RD) wrote:

>RD> I'm currently calling subprocess.call() on a batch file (in Windows)
>RD> that sets a few environment variables that are needed by further
>RD> processes started via subprocess.call(). How can I persist the
>RD> environment modifications by the first call() function? I've done my
>RD> own searching on this and I came up with nothing.


Environments are propagated down the subprocess chain, not up. (I don't
know Windows good enough but I think this is also true on Windows.) What
you could do is have the batch file print the environment, read it in
your script and passing that environment to the other subprocesses. But
then why would you do it in a batch file? You could as well copy the
setting of the environment variables in your Python script. Or if the
batch file is supplied by another source, parse it and extract the
environment variables from it.
--
Piet van Oostrum <>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email:
 
Reply With Quote
 
 
 
 
Aaron Brady
Guest
Posts: n/a
 
      05-01-2009
On May 1, 12:09*am, Robert Dailey <rcdai...@gmail.com> wrote:
> I'm currently calling subprocess.call() on a batch file (in Windows)
> that sets a few environment variables that are needed by further
> processes started via subprocess.call(). How can I persist the
> environment modifications by the first call() function? I've done my
> own searching on this and I came up with nothing.
>
> Help is appreciated.


I don't know if this will work, but you can try spawning a batch file
that calls the first program to set the variables, then executes the
second program. You might need to create that batch file by hand, as
well as the command line for the second process.

You can also try setting the env. variables in the parent process, and
restoring them after.
 
Reply With Quote
 
Robert Dailey
Guest
Posts: n/a
 
      05-05-2009
On May 1, 4:18*pm, Aaron Brady <castiro...@gmail.com> wrote:
> On May 1, 12:09*am, Robert Dailey <rcdai...@gmail.com> wrote:
>
> > I'm currently calling subprocess.call() on a batch file (in Windows)
> > that sets a few environment variables that are needed by further
> > processes started via subprocess.call(). How can I persist the
> > environment modifications by the first call() function? I've done my
> > own searching on this and I came up with nothing.

>
> > Help is appreciated.

>
> I don't know if this will work, but you can try spawning a batch file
> that calls the first program to set the variables, then executes the
> second program. *You might need to create that batch file by hand, as
> well as the command line for the second process.
>
> You can also try setting the env. variables in the parent process, and
> restoring them after.


Thanks for your help guys. Unfortunately both ideas will not work. I
guess I should have mentioned that the batch file in question is
vsvars32.bat, from the Visual Studio installation directory. I should
not modify this file, nor can I create a "wrapper" batch file as you
suggested, since I call several other batch files at different times.
There's about 6 other nmake calls I make that each is preceeded with a
call to vsvars32.bat. For now I'm using the && DOS operator, this
seems to work, however it is not ideal.
 
Reply With Quote
 
Gabriel Genellina
Guest
Posts: n/a
 
      05-05-2009
En Mon, 04 May 2009 23:25:42 -0300, Robert Dailey <>
escribió:

> Thanks for your help guys. Unfortunately both ideas will not work. I
> guess I should have mentioned that the batch file in question is
> vsvars32.bat, from the Visual Studio installation directory. I should
> not modify this file, nor can I create a "wrapper" batch file as you
> suggested, since I call several other batch files at different times.
> There's about 6 other nmake calls I make that each is preceeded with a
> call to vsvars32.bat. For now I'm using the && DOS operator, this
> seems to work, however it is not ideal.


There is nothing special about vsvars32.bat. If you execute it before your
first program (maybe inside a .cmd that calls vsvars32 and then your
program) then all the spawned programs will already see those settings. No
need to invoke it over and over.
Also, if you enter the same settings in the registry (so they become
persistent) you don't have to worry again.

--
Gabriel Genellina

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to import subprocess into my 'subprocess.py' file hiral Python 2 05-05-2010 12:56 PM
How to handle memory allocation i shared hosting environments? (GC.Collect) jdlwright@gmail.com ASP .Net 3 06-13-2006 05:36 PM
Shared cygwin & command.com environments? Jay Levitt Ruby 3 05-09-2006 12:10 PM
[Subprocess/Windows] subprocess module under Windows 98 Andreas Jung Python 2 11-02-2005 05:41 PM
Security issues with Asp.Net in Shared Hosting Environments Dinis Cruz ASP .Net Security 0 10-30-2003 09:56 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57