python: can you update the current shell from python?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
yes... python is can operate at the same level as any other terminal process, here's a very simple example of executing system commands (no capture of results other than exit code):
iret = os.system("ls -al")
if iret != 0:
print "Error - child terminated with signal ", iret
yes, that runs a system command, but it does nothing to my current shell.
os.system("setenv FOO bar")
will set an env var (in tcsh) for the time that python is running, but as soon as the python script terminates, so does that env var. I'm looking for a way to keep that env var around, or, more specifically, to keep a complete alias around.
Can I update the current shell with a python script?
I can run scripts from within python, but I'm not sure how to make python's changes stick in the current shell.
Sure arrange to source the output of a Python script then the Python script can output the text to set an environment variable (or three), and that will be sourced by the outer shell so changing the environment for subsequent commands.
well i'm having trouble with lot! I can't seem to do 'export LFS=/mnt/lfs', use declare or setenv (setenv is giving errors), even straight from shell? It's 6.10am an i'm off to bed, i'll look again tomorrow>>