modifying os.environ
Donn Cave
donn at u.washington.edu
Tue Apr 18 12:30:13 EDT 2000
Quoth Martin von Loewis <loewis at informatik.hu-berlin.de>:
| quinn at zloty.ugcs.caltech.edu (Quinn Dunkan) writes:
...
| > Or perhaps there's a better way to do the (common) thing I'm trying
| > to do: clean the environment to insure some minimum sane values. I
| > can't make a copy of the environ and then pass to execve() since
| > that doesn't help much for popen and system.
|
| You could implement popen and system yourself, starting from popen2
| (for example).
That may sound like the re-invention of the wheel, but there are
other improvements that can be made at the same time:
- eliminate system()'s sh -c 'shell command', which can be a
security liability in some situations. The shell can do
some really useful things, but if you don't need those things
you should be able to pass in an argv sequence and skip sh.
- Raise exception on exit status, complete with error output as
exception value. A bit of a pain to implement, and again not
not always the right thing to do, but usually it is the right
thing.
Donn Cave, University Computing Services, University of Washington
donn at u.washington.edu
More information about the Python-list
mailing list