problems with shell environment in os.system calls

Tim Roberts timr at probo.com
Fri Nov 1 02:55:29 EST 2002


jslavin at cfa.harvard.edu (Jon Slavin) wrote:

>I have a question regarding the shell environment in calls made via
>os.system, os.popen, etc.
>
>... My goal is to
>write a script that will source a C shell script that sets up various
>environment variables needed before executing the programs that really
>do all the work.

Before you go very far along this path, you need to think about what you
are doing.  Each call to os.system is independent: any environment variable
that gets set within that shell go away as soon as the shell exits.  Even
if you call "source", it is still running in a subshell that was created
specifically for the os.system call, and when it expires, so does its
environment.  You see the changes in your OWN environment (either in
os.environ or in any subsequent os.system calls).
--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list