summaryrefslogtreecommitdiffstats
path: root/Misc
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-02-17 18:40:02 (GMT)
committerGuido van Rossum <guido@python.org>1997-02-17 18:40:02 (GMT)
commit01094e408939689fc8df539c57ef994ca2c690e4 (patch)
tree42f94d6b6960e3361778749091fac4b05a58c7d6 /Misc
parent8651d27e0a0b44235b034f02fa59fca45d2156aa (diff)
downloadcpython-01094e408939689fc8df539c57ef994ca2c690e4.zip
cpython-01094e408939689fc8df539c57ef994ca2c690e4.tar.gz
cpython-01094e408939689fc8df539c57ef994ca2c690e4.tar.bz2
Change the question about os.environ changes not working -- it now
works unless you don't have putenv.
Diffstat (limited to 'Misc')
-rw-r--r--Misc/FAQ29
1 files changed, 10 insertions, 19 deletions
diff --git a/Misc/FAQ b/Misc/FAQ
index 6a7e645..078fc42 100644
--- a/Misc/FAQ
+++ b/Misc/FAQ
@@ -1295,25 +1295,16 @@ to sys.stderr when this happens.
4.18. Q. How do I change the shell environment for programs called
using os.popen() or os.system()? Changing os.environ doesn't work.
-A. Modifying the environment passed to subshells was left out of the
-interpreter because there seemed to be no well-established portable
-way to do it (in particular, some systems, have putenv(), others have
-setenv(), and some have none at all).
-
-However if all you want is to pass environment variables to the
-commands run by os.system() or os.popen(), there's a simple solution:
-prefix the command string with a couple of variable assignments and
-export statements. The following would be universal for popen:
-
- import os
- from commands import mkarg # nifty routine to add shell quoting
- def epopen(cmd, mode, env = {}):
- # env is a dictionary of environment variables
- prefix = ''
- for key, value in env.items():
- prefix = prefix + '%s=%s\n' % (key, mkarg(value)[1:])
- prefix = prefix + 'export %s\n' % key
- return os.popen(prefix + cmd, mode)
+A. You must be using either a version of python before 1.4, or on a
+(rare) system that doesn't have the putenv() library function.
+
+Before Python 1.4, modifying the environment passed to subshells was
+left out of the interpreter because there seemed to be no
+well-established portable way to do it (in particular, some systems,
+have putenv(), others have setenv(), and some have none at all). As
+of Python 1.4, almost all Unix systems *do* have putenv(), and so does
+the Win32 API, and thus the os module was modified so that changes to
+os.environ are trapped and the corresponding putenv() call is made.
4.19. Q. What is a class?