os.environ and os.path.chdir
Geoff Gerrietts
geoff at gerrietts.net
Fri Sep 19 19:30:03 EDT 2003
Quoting Yun Mao (maoy at cis.upenn.edu):
> Hi,
> How to make changes to os.environ and os.path.chdir still effective after
> I run the script? Currently, the changes are only good within my script. I
> would like the shell who called python myprog.py also gets the change..
> Thank you!
To the best of my knowledge, this can't be done. Depending on the
specific application, you might have several workarounds.
One is to exit into a new shell, using os.execve instead of sys.exit.
That creates "nested" shells, unless the user exec's your program
also.
Another is to exit by printing a list of commands, and expect that the
user will run your program like "eval `myprog.py`" to execute those
commands.
As far as I know, though, there's no way to actually hijack the user's
shell process. The user needs to explicitly give you that control.
--G.
--
Geoff Gerrietts "There is no fate that cannot be
<geoff at gerrietts net> surmounted by scorn." --Albert Camus
More information about the Python-list
mailing list