help w/ putenv

Jeff Epler jepler at unpythonic.net
Tue Dec 10 12:25:42 EST 2002


It's likely that PWD is set by your shell at startup and at each "cd".
If you want to start a script in another directory, you'll need to do
something like
     os.system("cd %s; printenv" % value)
(or use os.chdir in your Python script, possibly protected by fork+exec
so as not to affect the main program)

Remember, the argument to os.system is executed by sh -c.  Here's the
behavior under a shell, no python involved:
$ PWD="all your base are belong to us" sh -c printenv | grep PWD
PWD=/net/filesrv1/sd3a/users/jepler

For a variable the shell doesn't set, there's no problem
$ OTHER_VAR="for great justice" sh -c printenv | grep OTHER_VAR
OTHER_VAR=for great justice

Jeff




More information about the Python-list mailing list